diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 703dcb4..d0c30fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: name: Unit Test strategy: matrix: - lua_version: ["5.1", "5.2", "5.3", "luajit"] + lua_version: ["5.1", "5.2", "5.3", "luajit-openresty"] needs: - luacheck runs-on: ubuntu-latest @@ -73,7 +73,7 @@ jobs: - uses: actions/checkout@v4 - uses: leafo/gh-actions-lua@v10 with: - luaVersion: "luajit" + luaVersion: "luajit-openresty" - uses: leafo/gh-actions-luarocks@v4 - name: Run Tests run: | @@ -94,7 +94,7 @@ jobs: ls -l . echo "cat ./luacov.report.out" cat ./luacov.report.out - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v4 with: files: luacov.report.out env: diff --git a/spec/giturlparser_spec.lua b/spec/giturlparser_spec.lua index fa470b9..c431032 100644 --- a/spec/giturlparser_spec.lua +++ b/spec/giturlparser_spec.lua @@ -267,6 +267,25 @@ describe("giturlparser", function() assert_eq(path_obj.path_pos.start_pos, 16) assert_eq(path_obj.path_pos.end_pos, 25) end) + it("github.com:/repo.git", function() + local actual = giturlparser._parse_host("github.com:/repo.git", 1) + -- print(string.format("_make_host-5:%s\n", "github.com:/repo.git")) + -- print(string.format("_make_host-5:%s\n", inspect(actual))) + assert_eq(actual.host, "github.com") + assert_eq(actual.host_pos.start_pos, 1) + assert_eq(actual.host_pos.end_pos, 10) + assert_eq(actual.port, nil) + assert_eq(actual.port_pos, nil) + local path_obj = actual.path_obj + assert_eq(path_obj.org, nil) + assert_eq(path_obj.org_pos, nil) + assert_eq(path_obj.repo, "repo.git") + assert_eq(path_obj.repo_pos.start_pos, 13) + assert_eq(path_obj.repo_pos.end_pos, 20) + assert_eq(path_obj.path, "/repo.git") + assert_eq(path_obj.path_pos.start_pos, 12) + assert_eq(path_obj.path_pos.end_pos, 20) + end) end) describe("[_parse_host_with_omit_ssh]", function() diff --git a/src/giturlparser.lua b/src/giturlparser.lua index c90dd68..911d4b2 100644 --- a/src/giturlparser.lua +++ b/src/giturlparser.lua @@ -1,3 +1,4 @@ +-- local inspect = require("inspect") local M = {} -- utils { @@ -147,8 +148,6 @@ end M._parse_path = function(p, start) assert(type(start) == "number") - -- local inspect = require("inspect") - local endswith_slash = M._endswith(p, "/") local org = nil @@ -227,13 +226,24 @@ M._parse_host = function(p, start) -- find first slash '/' (after second ':'), the end position of port, start position of path local first_slash_pos = M._find(p, "/", first_colon_pos + 1) - if - type(first_slash_pos) == "number" - and first_slash_pos > first_colon_pos + 1 - then - -- port end with '/' - port, port_pos = M._make(p, first_colon_pos + 1, first_slash_pos - 1) - path_obj = M._parse_path(p, first_slash_pos) + -- print( + -- string.format( + -- "_parse_host, start:%s, first_colon_pos:%s, first_slash_pos:%s\n", + -- inspect(start), + -- inspect(first_colon_pos), + -- inspect(first_slash_pos) + -- ) + -- ) + if type(first_slash_pos) == "number" then + if first_slash_pos > first_colon_pos + 1 then + -- port end with '/' + port, port_pos = M._make(p, first_colon_pos + 1, first_slash_pos - 1) + path_obj = M._parse_path(p, first_slash_pos) + else + assert(first_slash_pos == first_colon_pos + 1) + -- port is empty, host still end with '/' + path_obj = M._parse_path(p, first_slash_pos) + end else -- path not found, port end until url end port, port_pos = M._make(p, first_colon_pos + 1, plen)