mirror of
https://github.com/golang/go
synced 2024-11-12 05:30:21 -07:00
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: Andrew Gerrand <adg@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
8e724e7bba
commit
7f9255c212
@ -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"},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user