Skip to content

Commit

Permalink
plumbing: transport, handle IPv6 while parsing endpoint. Fixes #740
Browse files Browse the repository at this point in the history
  • Loading branch information
ninedraft committed Jul 26, 2023
1 parent 36477e8 commit a105da8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plumbing/transport/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions plumbing/transport/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit a105da8

Please sign in to comment.