diff options
author | merlin <clamores.pro@gmail.com> | 2023-07-26 12:15:52 +0300 |
---|---|---|
committer | merlin <clamores.pro@gmail.com> | 2023-07-26 12:17:19 +0300 |
commit | a105da84747df637fa7913c3ab880be73019e502 (patch) | |
tree | 3c4598f02b91cbb6374211e088b6e9350c6ac5c1 /plumbing | |
parent | 36477e82f22623018ff170af8afc10c2c9bd50c5 (diff) | |
download | go-git-a105da84747df637fa7913c3ab880be73019e502.tar.gz |
plumbing: transport, handle IPv6 while parsing endpoint. Fixes #740
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/transport/common.go | 8 | ||||
-rw-r--r-- | plumbing/transport/common_test.go | 12 |
2 files changed, 19 insertions, 1 deletions
diff --git a/plumbing/transport/common.go b/plumbing/transport/common.go index 89bd3d5..c6a054a 100644 --- a/plumbing/transport/common.go +++ b/plumbing/transport/common.go @@ -227,11 +227,17 @@ func parseURL(endpoint string) (*Endpoint, error) { pass, _ = u.User.Password() } + host := u.Hostname() + if strings.Contains(host, ":") { + // IPv6 address + host = "[" + host + "]" + } + return &Endpoint{ Protocol: u.Scheme, User: user, Password: pass, - Host: u.Hostname(), + Host: host, Port: getPort(u), Path: getPath(u), }, nil diff --git a/plumbing/transport/common_test.go b/plumbing/transport/common_test.go index db11303..d9f12ab 100644 --- a/plumbing/transport/common_test.go +++ b/plumbing/transport/common_test.go @@ -198,3 +198,15 @@ func (s *SuiteCommon) TestFilterUnsupportedCapabilities(c *C) { FilterUnsupportedCapabilities(l) c.Assert(l.Supports(capability.MultiACK), Equals, false) } + +func (s *SuiteCommon) TestNewEndpointIPv6(c *C) { + // see issue https://github.com/go-git/go-git/issues/740 + // + // IPv6 host names are not being properly handled, which results in unhelpful + // error messages depending on the format used. + // + e, err := NewEndpoint("http://[::1]:8080/foo.git") + c.Assert(err, IsNil) + c.Assert(e.Host, Equals, "[::1]") + c.Assert(e.String(), Equals, "http://[::1]:8080/foo.git") +} |