diff --git a/git/url.go b/git/url.go index 1a3e97fd6..890ccbe1c 100644 --- a/git/url.go +++ b/git/url.go @@ -56,9 +56,7 @@ func ParseURL(rawURL string) (u *url.URL, err error) { u.Path = strings.TrimPrefix(u.Path, "/") } - if idx := strings.Index(u.Host, ":"); idx >= 0 { - u.Host = u.Host[0:idx] - } + u.Host = strings.TrimSuffix(u.Host, ":"+u.Port()) return } diff --git a/git/url_test.go b/git/url_test.go index f5b3b50d0..d31c1b817 100644 --- a/git/url_test.go +++ b/git/url_test.go @@ -126,6 +126,26 @@ func TestParseURL(t *testing.T) { Path: "/owner/repo.git", }, }, + { + name: "ssh, ipv6", + url: "ssh://git@[::1]/owner/repo.git", + want: url{ + Scheme: "ssh", + User: "git", + Host: "[::1]", + Path: "/owner/repo.git", + }, + }, + { + name: "ssh with port, ipv6", + url: "ssh://git@[::1]:22/owner/repo.git", + want: url{ + Scheme: "ssh", + User: "git", + Host: "[::1]", + Path: "/owner/repo.git", + }, + }, { name: "git+ssh", url: "git+ssh://example.com/owner/repo.git",