FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

validators.ip_address private kwarg does not work as intended · Issue #373 · python-validators/validators · GitHub

Repository navigation

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

Description

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.

Activity

  1. grleblanc commented on May 9, 2024

    Author

    PR Open to address the above, including unit tests.

  2. changed the title [-]validators.ip_address is_private does not work as intended[/-] [+]validators.ip_address private kwarg does not work as intended[/+] on May 9, 2024
  3. nandgator commented on May 10, 2024

    Collaborator

    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?

  4. grleblanc commented on May 10, 2024

    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

  5. grleblanc commented on May 10, 2024

    Author

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

  6. nandgator commented on May 11, 2024

    Collaborator

    Ah, I see the problem now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue: Works not as designed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL