Repository navigation
Conversation
Without re.ASCII, Python's \d also matches digits from other scripts, so "1٩٢.168.1.1" (Arabic-Indic 9 and 2) still validated. Also drops the blank line added above the import. test_numb3rs.py now covers leading zeros (000.001.010.100, 01.2.3.4, 1.2.3.04, 1.00.3.4), a lone 0 octet (0.0.0.0), and non-ASCII digits. Checked against Python's ipaddress.IPv4Address on 20,000 random inputs: no disagreements. Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
The existing IPv4 validation incorrectly accepts addresses containing leading zeros.
For example: 000.001.010.100 : Expected: False, Actual: True
Changes:
ipaddressmodule (it rejects them since 3.9.5).re.ASCII). Without it, Python's\dalso matches digits from other scripts, so1٩٢.168.1.1validated, onmaintoo.Tests:
test_numb3rs.pynow covers leading zeros (000.001.010.100,01.2.3.4,1.2.3.04,1.00.3.4), a lone0octet (0.0.0.0), and non-ASCII digits. The new tests fail onmain.pytest test_numb3rs.py: 3 passed.validateagainstipaddress.IPv4Addresson 20,000 random inputs: no disagreements.Co-authored-by: Claude noreply@anthropic.com