From 47efef6d70123fdbc3d212068dc32ce86ceed591 Mon Sep 17 00:00:00 2001 From: "Babak K. Shandiz" Date: Fri, 5 Apr 2024 10:54:55 +0100 Subject: [PATCH] Fix parsing IPv6 remote URLs (#8893) Signed-off-by: Babak K. Shandiz --- git/url.go | 4 +--- git/url_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) 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",