aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/url/url.go4
-rw-r--r--src/net/url/url_test.go23
2 files changed, 21 insertions, 6 deletions
diff --git a/src/net/url/url.go b/src/net/url/url.go
index a697548801..6afa30f162 100644
--- a/src/net/url/url.go
+++ b/src/net/url/url.go
@@ -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)
diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go
index a7543d6fd4..6084facacc 100644
--- a/src/net/url/url_test.go
+++ b/src/net/url/url_test.go
@@ -507,6 +507,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{
Scheme: "http",
@@ -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) {