Hints kitten: validate IPs with ipaddress

On the initial commit of this feature, IPs were just matched with a
very simple regex that prioritised simplicity/readability over
accuracy.

This commit adds a postprocessor for ip matches that makes use of
Python's `ipaddress` in the standard library to validate all the IP
matches.

This way we don't need huge and complex regex patterns to match _and_
validate the IPs, and we can just use `ipaddress` to abstract us from
implementing all the validation logic into the regex pattern.
This commit is contained in:
Sighery
2020-10-04 22:46:00 +02:00
parent b4415c90f9
commit 10533c3eba
2 changed files with 29 additions and 4 deletions

View File

@@ -48,8 +48,9 @@ class TestHints(BaseTest):
('2001:DB8::FF00:42:8329', ['2001:DB8::FF00:42:8329']),
('0000:0000:0000:0000:0000:0000:0000:0001', ['0000:0000:0000:0000:0000:0000:0000:0001']),
('::1', ['::1']),
# The regex doesn't check for validity
('255.255.255.256', ['255.255.255.256']),
# Invalid IPs won't match
('255.255.255.256', []),
(':1', []),
)
for testcase, expected in testcases: