Repository navigation
Reject non-ASCII digits and letters in pt.cc and iso6346 - #527
Open
adityakale2002 wants to merge 1 commit into
Open
adityakale2002 wants to merge 1 commit into
adityakale2002 wants to merge 1 commit into
Conversation
The regular expressions used \d and \w, which match non-ASCII digits and letters for str patterns. Values such as '00000000 0 ZZ4' written with Arabic-Indic digits passed the format check and then made validate() and is_valid() raise ValueError instead of a ValidationError. Use explicit ASCII character classes instead. Co-Authored-By: Claude Sonnet 5.5 <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.
pt.ccandiso6346build their format check with\d/\w. Forstrpatterns these also match non-ASCII digits and letters, so such values pass the format check and then makevalidate()/is_valid()raiseValueError(fromstr.index) instead of aValidationError.is_valid()should never raise. This switches both patterns to explicit ASCII classes ([0-9],[A-Z]for the three-letter owner code, which ISO 6346 defines as capital letters). Doctests are added totests/test_pt_cc.doctestandtests/test_iso6346.doctest; they fail before the change and pass after, and the full suite passes.I found this by fuzzing every module's
validate/is_valid/compactwith random input. Some other modules (damm,verhoeff,lei,iso11649,eg.tn,iso7064.*) accept non-ASCII digits as valid rather than crashing. I left those out to keep this small, but can follow up if you want them handled.Written with the help of Claude Code, and I reviewed the change and ran the tests.
🤖 Generated with Claude Code