]> Cypherpunks repositories - gostls13.git/commitdiff
net: revise IP.String result for malformed IP address to add ? back
authorRuss Cox <rsc@golang.org>
Tue, 24 May 2016 00:40:52 +0000 (20:40 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 24 May 2016 13:54:31 +0000 (13:54 +0000)
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>

src/net/ip.go
src/net/ip_test.go

index 06d349b5f2c3d0feb71471b6b899f34615252283..d0c82630b57830efbb3106eb737470d04052a743 100644 (file)
@@ -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
 }
index 87c12133c3356753796ec3d1d0f2295042c1921d..b6ac26da05b84abfd666af7954274c3a87f76fbc 100644 (file)
@@ -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"},
        },