Skip to content

validators.ip_address private kwarg does not work as intended #373

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

Closed
grleblanc opened this issue May 9, 2024 · 5 comments · Fixed by #374
Closed

validators.ip_address private kwarg does not work as intended #373

grleblanc opened this issue May 9, 2024 · 5 comments · Fixed by #374
Labels
bug Issue: Works not as designed

Comments

@grleblanc
Copy link

Python: 3.12
Valdiators: 0.28.1

validators.ip_address does not properly handle the scenario when private=False

Result:

❯ python3.11
iPython 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import validators
>>> a = "1.1.1.1"
>>> validators.ipv4(a)
True
>>> validators.ipv4(a, private=True)
ValidationError(func=ipv4, args={'value': '1.1.1.1', 'private': True})
>>> validators.ipv4(a, private=False)
ValidationError(func=ipv4, args={'value': '1.1.1.1', 'private': False})

Expected Result:

❯ python3.11
iPython 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import validators
>>> a = "1.1.1.1"
>>> validators.ipv4(a)
True
>>> validators.ipv4(a, private=True)
ValidationError(func=ipv4, args={'value': '1.1.1.1', 'private': True})
>>> validators.ipv4(a, private=False)
True

I also noticed there are no unit tests that cover the above scenarios.

@grleblanc
Copy link
Author

PR Open to address the above, including unit tests.

@grleblanc grleblanc changed the title validators.ip_address is_private does not work as intended validators.ip_address private kwarg does not work as intended May 9, 2024
@yozachar
Copy link
Collaborator

yozachar commented May 10, 2024

Hi, I do not understand. 1.1.1.1 does not fall into any of these categories.

"10.",  # private
"192.168.",  # private
"169.254.",  # link-local
"127.",  # localhost
"0.0.0.0",  # loopback

See:

Sure, some modifications are needed in the ranges, but ...

How is 1.1.1.1 a private address?

@grleblanc
Copy link
Author

If I specify private=False we want validators to check to see if the IP address given is not private

If you read my original issue description under the "expected" outcome you will see that reflected there.

Expected Result:


❯ python3.11
iPython 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import validators
>>> a = "1.1.1.1"
>>> validators.ipv4(a)
True
>>> validators.ipv4(a, private=True)
ValidationError(func=ipv4, args={'value': '1.1.1.1', 'private': True})
>>> validators.ipv4(a, private=False)
True

Specifically

>>> a = "1.1.1.1"
>>> validators.ipv4(a, private=False)
True

Right now there is only a way to check if an IP is private

@grleblanc
Copy link
Author

grleblanc commented May 10, 2024

Furthermore, the current functionality of private=False does nothing.

@yozachar
Copy link
Collaborator

Ah, I see the problem now. Thanks!

@yozachar yozachar added the bug Issue: Works not as designed label May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue: Works not as designed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants