net: ParseIP should return nil if :: doesn't expand in an IPv6 address.

Per RFC 4291, 'The use of "::" indicates one or more groups of 16 bits of zeros.'
Fixes #6628

R=golang-dev, rsc, minux.ma, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/15990043
This commit is contained in:
Alex A Skinner 2013-12-20 21:29:28 +09:00 committed by Mikio Hara
parent eb7ed0d626
commit 487dff1852
2 changed files with 4 additions and 0 deletions

View File

@ -623,6 +623,9 @@ func parseIPv6(s string, zoneAllowed bool) (ip IP, zone string) {
for k := ellipsis + n - 1; k >= ellipsis; k-- {
ip[k] = 0
}
} else if ellipsis >= 0 {
// Ellipsis must represent at least one 0 group.
return nil, zone
}
return ip, zone
}

View File

@ -25,6 +25,7 @@ var parseIPTests = []struct {
{"fe80::1%lo0", nil},
{"fe80::1%911", nil},
{"", nil},
{"a1:a2:a3:a4::b1:b2:b3:b4", nil}, // Issue 6628
}
func TestParseIP(t *testing.T) {