(#501) make IP.String() method return something sensible

This commit is contained in:
Vincent Janelle
2023-01-07 00:16:01 -08:00
committed by Ron Evans
parent 0b6e1d0e78
commit b1c9612158
2 changed files with 18 additions and 1 deletions
+4 -1
View File
@@ -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.
+14
View File
@@ -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")
}