Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand All @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions spec/giturlparser_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
28 changes: 19 additions & 9 deletions src/giturlparser.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- local inspect = require("inspect")
local M = {}

-- utils {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading