Fix parsing IPv6 remote URLs (#8893)

Signed-off-by: Babak K. Shandiz <babak.k.shandiz@gmail.com>
This commit is contained in:
Babak K. Shandiz 2024-04-05 10:54:55 +01:00 committed by GitHub
parent 2c53d7c9a8
commit 47efef6d70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View file

@ -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
}

View file

@ -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",