Skip to content

Commit

Permalink
fix(url): fix host ends with a colon but port is empty (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 authored Nov 22, 2024
1 parent 606060e commit 3ed7409
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ jobs:
cp ~/.commons.nvim/version.txt ./lua/gitlinker/commons/version.txt
cd ./lua/gitlinker/commons
find . -type f -name '*.lua' -exec sed -i 's/require("commons/require("gitlinker.commons/g' {} \;
- name: Install giturlparser.lua
if: ${{ github.ref != 'refs/heads/master' }}
shell: bash
run: |
echo "pwd"
echo $PWD
git clone --depth=1 https://github.com/linrongbin16/giturlparser.lua.git ~/.giturlparser.lua
cp ~/.giturlparser.lua/src/giturlparser.lua ./lua/gitlinker/giturlparser.lua
- uses: stefanzweifel/git-auto-commit-action@v5
if: ${{ github.ref != 'refs/heads/master' }}
with:
Expand Down
28 changes: 19 additions & 9 deletions lua/gitlinker/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
20 changes: 20 additions & 0 deletions spec/gitlinker_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,26 @@ describe("gitlinker", function()
)
assert_eq(actual, routers.github_browse(lk))
end)
it("ssh://[email protected]:/myorg/myrepo.git", function()
local lk = {
remote_url = "ssh://[email protected]:/myorg/myrepo.git",
username = "git",
host = "github.com",
org = "myorg",
repo = "myrepo.git",
rev = "399b1d05473c711fc5592a6ffc724e231c403486",
file = "lua/gitlinker/logger.lua",
lstart = 1,
lend = 1,
file_changed = false,
}--[[@as gitlinker.Linker]]
local actual = gitlinker._browse(lk)
assert_eq(
actual,
"https://github.com/myorg/myrepo/blob/399b1d05473c711fc5592a6ffc724e231c403486/lua/gitlinker/logger.lua?plain=1#L1"
)
assert_eq(actual, routers.github_browse(lk))
end)
it("ssh://[email protected] with same lstart/lend", function()
local lk = {
remote_url = "ssh://[email protected]/linrongbin16/gitlinker.nvim.git",
Expand Down

0 comments on commit 3ed7409

Please sign in to comment.