Commit 7f9255c2 authored by Russ Cox's avatar Russ Cox

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 <rsc@golang.org>
Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8e724e7b
......@@ -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
}
......
......@@ -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"},
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment