mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-23 08:47:47 +02:00
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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user