Repository navigation
Require ASCII digits in Finnish, French and Indian identifiers - #532
Merged
Merged
Conversation
fi_ssn(), fr_ssn(), ind_aadhar() and ind_pan() matched digits with \d and separators with \s, which for str patterns match any Unicode decimal digit or whitespace, and the checksums use int(), which accepts the same digits. An identifier with one digit swapped for its Arabic-Indic or fullwidth form, or a space for a no-break space, still validated. Add re.ASCII to the four patterns.
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.
fi_ssn(),fr_ssn(),ind_aadhar()andind_pan()match their digits with\d, andfr_ssn()andind_aadhar()their separators with\s. Forstrpatterns these match any Unicode decimal digit and any Unicode whitespace (Pythonredocs). The checksums then run onint(), which accepts the same digits (docs). So an identifier with one digit or space swapped for a lookalike still validates:This is the same issue #519 fixed for Spanish identifiers. I found these by taking every validator's documented valid example, replacing one ASCII digit at a time with its Arabic-Indic or fullwidth form, and checking which validators still accept the result.
card_number(), its brand validators,uuid()andcron()show up as well; #508 covers those.Change
Add
re.ASCIIto the four patterns, so\dmatches only[0-9]and\sonly[ \t\n\r\f\v].Tests
Each new case is a valid identifier with exactly one character replaced, so the tests isolate the non-ASCII character. All 11 fail on master and pass here. The full suite (1529 tests), doctests,
ruff check,ruff formatandpyrightpass. A fuzz comparison against master (20,000 mutations per validator) found nothing newly accepted, and every newly rejected input contains a non-ASCII character.