Whole file

python-validators/validators

The author described this change as fix(ip_address): properly handle private is false. It counts as a record because the check below fails on the code as it stood at d46cd586b and passes on 7c0e60539, with nothing else changed between the two runs.

Fix saved2024-05-09
Sharing licenceMIT · LICENSE.txt
Change size+4 3

What the code was meant to do, written into the code itself as a save note

fix(ip_address): properly handle private is false

The change

1919 def _check_private_ip(value: str, is_private: Optional[bool]):
2020 if is_private is None:
2121 return True
22- if is_private and (
22+ if (
2323 any(
2424 value.startswith(l_bit)
2525 for l_bit in {
3333 or re.match(r"^172\.(?:1[6-9]|2\d|3[0-1])\.", value) # private
3434 or re.match(r"^(?:22[4-9]|23[0-9]|24[0-9]|25[0-5])\.", value) # broadcast
3535 ):
36- return True
37- return False
36+ return bool(is_private)
37+ else:
38+ return not bool(is_private)
3839
3940
4041 @validator

The check that tells the two apart

failpass·tests/test_ip_address.py::test_returns_valid_on_private_ipv4_address[1.1.1.1-False]

Check file tests/test_ip_address.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itd46cd586bdd6b9946d5d421f009794a25650f72e
Broken version dated2024-05-07
Modulevalidators.ip_address
Units changed_check_private_ip
Fingerprint2ff85b21a7bd416f
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in python-validators/validators