Skip to content

Commit

Permalink
added ipv4 digit lengts validation (#191)
Browse files Browse the repository at this point in the history
Co-authored-by: Norbert Chmiel <Norbert.Chmiel@pbkm.pl>
  • Loading branch information
Norbiox and Norbert Chmiel committed Jun 5, 2022
1 parent 4afa243 commit c056d64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/test_ipv4.py
Expand Up @@ -19,6 +19,7 @@ def test_returns_true_on_valid_ipv4_address(address):
('1278.0.0.1',),
('127.0.0.abc',),
('900.200.100.75',),
('0127.0.0.1',),
])
def test_returns_failed_validation_on_invalid_ipv4_address(address):
assert isinstance(ipv4(address), ValidationFailure)
8 changes: 6 additions & 2 deletions validators/ip_address.py
Expand Up @@ -23,8 +23,12 @@ def ipv4(value):
:param value: IP address string to validate
"""
groups = value.split('.')
if len(groups) != 4 or any(not x.isdigit() for x in groups):
groups = value.split(".")
if (
len(groups) != 4
or any(not x.isdigit() for x in groups)
or any(len(x) > 3 for x in groups)
):
return False
return all(0 <= int(part) < 256 for part in groups)

Expand Down

0 comments on commit c056d64

Please sign in to comment.