{"::ffff:127.1.2.3", IPv4(127, 1, 2, 3)},
{"::ffff:7f01:0203", IPv4(127, 1, 2, 3)},
{"0:0:0:0:0000:ffff:127.1.2.3", IPv4(127, 1, 2, 3)},
- {"0:0:0:0:000000:ffff:127.1.2.3", IPv4(127, 1, 2, 3)},
{"0:0:0:0::ffff:127.1.2.3", IPv4(127, 1, 2, 3)},
{"2001:4860:0:2001::68", IP{0x20, 0x01, 0x48, 0x60, 0, 0, 0x20, 0x01, 0, 0, 0, 0, 0, 0, 0x00, 0x68}},
{"fe80::1%lo0", nil},
{"fe80::1%911", nil},
{"", nil},
+ //6 zeroes in one group
+ {"0:0:0:0:000000:ffff:127.1.2.3", nil},
+ //5 zeroes in one group edge case
+ {"0:0:0:0:00000:ffff:127.1.2.3", nil},
{"a1:a2:a3:a4::b1:b2:b3:b4", nil}, // Issue 6628
{"127.001.002.003", nil},
{"::ffff:127.001.002.003", nil},
} else {
break
}
+ if off > 3 {
+ //more than 4 digits in group, fail.
+ return Addr{}, parseAddrError{in: in, msg: "each group must have 4 or less digits", at: s}
+ }
if acc > math.MaxUint16 {
// Overflow, fail.
return Addr{}, parseAddrError{in: in, msg: "IPv6 field has value >=2^16", at: s}
"fe80:1?:1",
// IPv6 with truncated bytes after single colon.
"fe80:",
+ // IPv6 with 5 zeros in last group
+ "0:0:0:0:0:ffff:0:00000",
+ // IPv6 with 5 zeros in one group and embedded IPv4
+ "0:0:0:0:00000:ffff:127.1.2.3",
}
for _, s := range invalidIPs {
{mustIP("::ffff:127.1.2.3"), true, mustIP("127.1.2.3")},
{mustIP("::ffff:7f01:0203"), true, mustIP("127.1.2.3")},
{mustIP("0:0:0:0:0000:ffff:127.1.2.3"), true, mustIP("127.1.2.3")},
- {mustIP("0:0:0:0:000000:ffff:127.1.2.3"), true, mustIP("127.1.2.3")},
{mustIP("0:0:0:0::ffff:127.1.2.3"), true, mustIP("127.1.2.3")},
{mustIP("::1"), false, mustIP("::1")},
{mustIP("1.2.3.4"), false, mustIP("1.2.3.4")},
// parseWord converts a 16-bit hex string into its corresponding
// two-byte value.
func parseWord(s string) (byte, byte, error) {
+ if(len(s) > 4) {
+ return 0, 0, fmt.Errorf("parseWord(%q): invalid word", s)
+ }
ret, err := strconv.ParseUint(s, 16, 16)
if err != nil {
return 0, 0, err