From 6b5535f0d1d228c381651200c574be6b2a5f2e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20Andr=C3=A9=20Elsfjordstrand=20Beck?= Date: Tue, 21 May 2024 14:11:25 +0200 Subject: [PATCH] fix: IPv4 to string on 32-bit --- url/hostparser.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/url/hostparser.go b/url/hostparser.go index 3a75c61..1adcc72 100644 --- a/url/hostparser.go +++ b/url/hostparser.go @@ -189,7 +189,6 @@ func (p *parser) parseIPv4(u *Url, input string) (string, error) { for counter, n := range numbers { ipv4 += IPv4Addr(n * int64(math.Pow(256, float64(3-counter)))) } - u.isIPv4 = true return ipv4.String(), nil } @@ -419,17 +418,11 @@ func (address *IPv6Addr) String() string { type IPv4Addr uint32 -func (address *IPv4Addr) String() string { - output := "" - n := int(*address) - for i := 1; i <= 4; i++ { - output = strconv.Itoa(n%256) + output - if i != 4 { - output = "." + output - } - n = n / 256 - } - return output +func (address IPv4Addr) String() string { + return strconv.Itoa(int(address>>24)) + "." + + strconv.Itoa(int((address>>16)&0xFF)) + "." + + strconv.Itoa(int((address>>8)&0xFF)) + "." + + strconv.Itoa(int(address&0xFF)) } var idnaProfile = idna.New(