You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Why 127.0.0.1 valid and how to validate only cidr notation #290
So when cidr=True and strict=True, if host bits are set in the supplied IP address, it raises a validation error.
$ python -c "from validators import ipv4; print(ipv4('192.168.1.5/24', strict=True))"ValidationError(func=ipv4, args={'reason': '192.168.1.5/24 has host bits set', 'value': '192.168.1.5/24', 'strict': True})
$ # Expected a network address like 192.168.1.0 (where network part is `192.168.1` and host part is `0`)
I'm pondering on a solution, I'll update you when I'm ready. Meanwhile feel free to comment below.
Activity
nandgator commentedon Aug 23, 2023
@mertcangokgoz, thanks for raising this issue, I see now that the
strictparameter is confusing. Reference source:validators/src/validators/ip_address.py
Lines 58 to 65 in 9e94fee
Here's what
strictcurrently does.cidr=Trueand the input string has a/.So when
cidr=Trueandstrict=True, if host bits are set in the supplied IP address, it raises a validation error.I'm pondering on a solution, I'll update you when I'm ready. Meanwhile feel free to comment below.
nandgator commentedon Aug 23, 2023
Here's the patch
PRs are welcome.
fix: strict CIDR IP validation; bump version
fix: strict CIDR IP validation; bump version