diff --git a/net/net.go b/net/net.go index 8654820..f28da84 100644 --- a/net/net.go +++ b/net/net.go @@ -357,7 +357,10 @@ func ParseIP(s string) IP { // String returns the string form of the IP address ip. func (ip IP) String() string { - return string(ip) + if len(ip) < 4 { + return "" + } + return strconv.Itoa(int(ip[0])) + "." + strconv.Itoa(int(ip[1])) + "." + strconv.Itoa(int(ip[2])) + "." + strconv.Itoa(int(ip[3])) } // Conn is a generic stream-oriented network connection. diff --git a/net/net_test.go b/net/net_test.go new file mode 100644 index 0000000..e9ac662 --- /dev/null +++ b/net/net_test.go @@ -0,0 +1,14 @@ +package net + +import ( + "testing" + + qt "github.com/frankban/quicktest" +) + +func TestIPAddressString(t *testing.T) { + c := qt.New(t) + ipaddr := ParseIP("127.0.0.1") + + c.Assert(ipaddr.String(), qt.Equals, "127.0.0.1") +}