Remove interface names from IPv6
This commit is contained in:
parent
12fae2ebb8
commit
8946dd1898
2 changed files with 7 additions and 3 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -91,10 +92,11 @@ func (ip *Checker) ContainsIP(addr net.IP) bool {
|
|||
}
|
||||
|
||||
func parseIP(addr string) (net.IP, error) {
|
||||
userIP := net.ParseIP(addr)
|
||||
if userIP == nil {
|
||||
parsedAddr, err := netip.ParseAddr(addr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't parse IP from address %s", addr)
|
||||
}
|
||||
|
||||
return userIP, nil
|
||||
ip := parsedAddr.As16()
|
||||
return ip[:], nil
|
||||
}
|
||||
|
|
|
@ -258,6 +258,7 @@ func TestContainsIsAllowed(t *testing.T) {
|
|||
"2a03:4000:6:d080::42",
|
||||
"fe80::1",
|
||||
"fe80:aa00:00bb:4232:ff00:eeee:00ff:1111",
|
||||
"fe80:aa00:00bb:4232:ff00:eeee:00ff:1111%vEthernet",
|
||||
"fe80::fe80",
|
||||
"1.2.3.1",
|
||||
"1.2.3.32",
|
||||
|
@ -271,6 +272,7 @@ func TestContainsIsAllowed(t *testing.T) {
|
|||
rejectIPs: []string{
|
||||
"2a03:4000:7:d080::",
|
||||
"2a03:4000:7:d080::1",
|
||||
"2a03:4000:7:d080::1%vmnet1",
|
||||
"4242::1",
|
||||
"1.2.16.1",
|
||||
"1.2.32.1",
|
||||
|
|
Loading…
Reference in a new issue