Repository navigation
Use ASCII-only character checks in remaining format validation - #531
Open
adityakale2002 wants to merge 1 commit into
Open
adityakale2002 wants to merge 1 commit into
adityakale2002 wants to merge 1 commit into
Conversation
Regular expressions using \d and the str.isalpha() and str.isalnum() methods match characters outside of 0-9 and A-Z (e.g. ARABIC-INDIC DIGIT THREE or LATIN SMALL LETTER E WITH ACUTE), so numbers containing them were accepted as valid by br.cnpj, fi.hetu, is_.kennitala, ro.onrc, si.maticna, ad.nrt, es.cae and eu.banknote. Use explicit ASCII character classes and comparisons 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.
Third and last part of the non-ASCII character cleanup, after #527 (
pt.cc,iso6346) and #528 (checksum modules,ie.pps). Like those, it is independent of them and based on master.\d,str.isalpha()andstr.isalnum()also match characters outside0-9/A-Z(e.g.'٣', ARABIC-INDIC DIGIT THREE, or'é'), so these validators accept numbers containing them:\din a regex:br.cnpj,fi.hetu,is_.kennitala,ro.onrc,si.maticnaisalpha()/isalnum():ad.nrtandes.cae(control letter),eu.banknote(two-character prefix)This switches them to explicit ASCII classes (
[0-9]) and'A' <= c <= 'Z'comparisons. Fullwidth digits are untouched, sinceutil.clean()maps those to ASCII on purpose.Found by replacing single characters of every known-valid number in the doctests with non-ASCII ones and checking which validators still accepted the result. I left
fr.accise,eu.exciseandgs1_128alone: they do not validate the affected character at all.Tests: one doctest per module in the existing
tests/test_*.doctestfiles. All fail before the change and pass after; the full suite and flake8 pass.Written with the help of Claude Code, and I reviewed the change and ran the tests.
🤖 Generated with Claude Code