]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "net/url: disallow raw IPv6 addresses in host"
authorDamien Neil <dneil@google.com>
Tue, 14 Oct 2025 16:34:11 +0000 (09:34 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 14 Oct 2025 17:43:46 +0000 (10:43 -0700)
This reverts commit e3be2d1b2b68d960398a343805f77052d5decb22.

Reason for revert: Causes extensive failures in Google-internal testing.

Change-Id: I232f547fc326dff7df959d25f3a89777ea33b201
Reviewed-on: https://go-review.googlesource.com/c/go/+/711800
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/net/url/url.go
src/net/url/url_test.go

index a69754880149a965fee9c812100afdb964c51b61..6afa30f162bd2589d98992bdcca9f1fecc369a7f 100644 (file)
@@ -698,9 +698,7 @@ func parseHost(host string) (string, error) {
                        return "", errors.New("invalid IP-literal")
                }
                return "[" + unescapedHostname + "]" + unescapedColonPort, nil
-       } else if i := strings.Index(host, ":"); i != -1 {
-               // IPv4address / reg-name
-               // E.g. 1.2.3.4, 1.2.3.4:80, example.com, example.com:80
+       } else if i := strings.LastIndex(host, ":"); i != -1 {
                colonPort := host[i:]
                if !validOptionalPort(colonPort) {
                        return "", fmt.Errorf("invalid port %q after host", colonPort)
index a7543d6fd40b1e3d521e0aa764b27116eebcc9e5..6084facacc0519b0caebd232b67d0f8edbf43898 100644 (file)
@@ -506,6 +506,26 @@ var urltests = []URLTest{
                },
                "",
        },
+       {
+               // Malformed IPv6 but still accepted.
+               "http://2b01:e34:ef40:7730:8e70:5aff:fefe:edac:8080/foo",
+               &URL{
+                       Scheme: "http",
+                       Host:   "2b01:e34:ef40:7730:8e70:5aff:fefe:edac:8080",
+                       Path:   "/foo",
+               },
+               "",
+       },
+       {
+               // Malformed IPv6 but still accepted.
+               "http://2b01:e34:ef40:7730:8e70:5aff:fefe:edac:/foo",
+               &URL{
+                       Scheme: "http",
+                       Host:   "2b01:e34:ef40:7730:8e70:5aff:fefe:edac:",
+                       Path:   "/foo",
+               },
+               "",
+       },
        {
                "http://[2b01:e34:ef40:7730:8e70:5aff:fefe:edac]:8080/foo",
                &URL{
@@ -715,9 +735,6 @@ var parseRequestURLTests = []struct {
        {"https://[0:0::test.com]:80", false},
        {"https://[2001:db8::test.com]", false},
        {"https://[test.com]", false},
-       {"https://1:2:3:4:5:6:7:8", false},
-       {"https://1:2:3:4:5:6:7:8:80", false},
-       {"https://example.com:80:", false},
 }
 
 func TestParseRequestURI(t *testing.T) {