From: Russ Cox Date: Tue, 24 May 2016 00:40:52 +0000 (-0400) Subject: net: revise IP.String result for malformed IP address to add ? back X-Git-Tag: go1.7beta1~121 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7f9255c2120f784c334431661145ee89e75f64fe;p=gostls13.git net: revise IP.String result for malformed IP address to add ? back In earlier versions of Go the result was simply "?". A change in this cycle made the result echo back the hex bytes of the address, which is certainly useful, but now the result is not clearly indicating an error. Put the "?" back, at the beginning of the hex string, to make the invalidity of the string clearer. Change-Id: I3e0f0b6a005601cd98d982a62288551959185b40 Reviewed-on: https://go-review.googlesource.com/23376 Run-TryBot: Russ Cox Reviewed-by: Andrew Gerrand TryBot-Result: Gobot Gobot --- diff --git a/src/net/ip.go b/src/net/ip.go index 06d349b5f2..d0c82630b5 100644 --- a/src/net/ip.go +++ b/src/net/ip.go @@ -272,7 +272,7 @@ func (ip IP) String() string { uitoa(uint(p4[3])) } if len(p) != IPv6len { - return hexString(ip) + return "?" + hexString(ip) } // Find longest run of zeros. @@ -338,7 +338,7 @@ func (ip IP) MarshalText() ([]byte, error) { return []byte(""), nil } if len(ip) != IPv4len && len(ip) != IPv6len { - return nil, &AddrError{Err: "invalid IP address", Addr: ip.String()} + return nil, &AddrError{Err: "invalid IP address", Addr: hexString(ip)} } return []byte(ip.String()), nil } diff --git a/src/net/ip_test.go b/src/net/ip_test.go index 87c12133c3..b6ac26da05 100644 --- a/src/net/ip_test.go +++ b/src/net/ip_test.go @@ -225,7 +225,7 @@ var ipStringTests = []struct { // Opaque byte sequence { IP{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, - "0123456789abcdef", + "?0123456789abcdef", nil, &AddrError{Err: "invalid IP address", Addr: "0123456789abcdef"}, },