File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 55
66
77@pytest .mark .parametrize (('address' ,), [
8+ ('::' ,),
89 ('::1' ,),
9- ('dead:beef:0:0:0:0:42:1' ,),
10+ ('1::' ,),
11+ ('dead:beef:0:0:0:0000:42:1' ,),
1012 ('abcd:ef::42:1' ,),
1113 ('0:0:0:0:0:ffff:1.2.3.4' ,),
1214 ('::192.168.30.2' ,),
@@ -21,6 +23,10 @@ def test_returns_true_on_valid_ipv6_address(address):
2123 ('abcd:1234::123::1' ,),
2224 ('1:2:3:4:5:6:7:8:9' ,),
2325 ('abcd::1ffff' ,),
26+ ('1111:' ,),
27+ (':8888' ,),
28+ (':1.2.3.4' ,),
29+ ('18:05' ,),
2430])
2531def test_returns_failed_validation_on_invalid_ipv6_address (address ):
2632 assert isinstance (ipv6 (address ), ValidationFailure )
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ def ipv4_cidr(value):
5757@validator
5858def ipv6 (value ):
5959 """
60- Return whether or not given value is a valid IP version 6 address
60+ Return whether a given value is a valid IP version 6 address
6161 (including IPv4-mapped IPv6 addresses).
6262
6363 This validator is based on `WTForms IPAddress validator`_.
@@ -112,9 +112,13 @@ def ipv6(value):
112112 if not 0 <= num <= 65536 :
113113 return False
114114
115- if count_blank < 2 :
115+ if count_blank == 0 and len ( ipv6_groups ) == max_groups :
116116 return True
117- elif count_blank == 2 and not ipv6_groups [0 ] and not ipv6_groups [1 ]:
117+ elif count_blank == 1 and ipv6_groups [- 1 ] and ipv6_groups [0 ]:
118+ return True
119+ elif count_blank == 2 and (not ipv6_groups [0 ] or not ipv6_groups [- 1 ]):
120+ return True
121+ elif count_blank == 3 and len (ipv6_groups ) == 3 :
118122 return True
119123 return False
120124
You can’t perform that action at this time.
0 commit comments