Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ipv4 digit lengts validation #191

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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