Skip to content

Reject non-ASCII digits in checksum modules and ie.pps - #528

Open
adityakale2002 wants to merge 1 commit into
arthurdejong:masterfrom
adityakale2002:fix/non-ascii-digits-accepted
Open

adityakale2002 wants to merge 1 commit into
arthurdejong:masterfrom
adityakale2002:fix/non-ascii-digits-accepted

Conversation

@adityakale2002

Copy link
Copy Markdown

Follow-up to #527. int() accepts digits from other scripts (e.g. '٣', ARABIC-INDIC DIGIT THREE), so these modules treat such characters as ordinary digits:

  • damm, verhoeff, iso7064.mod_11_2, mod_11_10 and mod_97_10: validate() accepts them as valid input. lei and iso11649 build on mod_97_10, so they accepted them as well.
  • ie.pps: the format check uses \d, which also matches them.
>>> from stdnum import lei
>>> lei.is_valid('٢١٣٨٠٠KUD٨LAJWSQ٩D١٥')  # 213800KUD8LAJWSQ9D15
True

stdnum.util.isdigits() already notes that non-ASCII digits are not wanted, so this makes these modules consistent with it. The checksum modules now raise InvalidFormat for non-ASCII input (str(number) is used so non-string input keeps raising only validation errors, as test_robustness requires), and ie.pps uses [0-9].

I left eg.tn alone since it converts Arabic digits on purpose. I found the affected modules by converting every valid number in the doctests to Arabic-Indic digits and checking which validators still accepted them.

Tests: one doctest in each affected module's test file (damm, verhoeff, iso7064, ie_pps, lei, iso11649). All fail before the change and pass after; the full suite passes.

Written with the help of Claude Code, and I reviewed the change and ran the tests.

🤖 Generated with Claude Code

int() accepts digits from other scripts (e.g. ARABIC-INDIC DIGIT ONE), so
the damm, verhoeff and iso7064 mod_11_2, mod_11_10 and mod_97_10 modules
treated such values as valid digits. This also affected the lei and
iso11649 modules which build on mod_97_10. The ie.pps format check used
\d which has the same problem.

Reject non-ASCII input with InvalidFormat and use an explicit ASCII
character class in ie.pps.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant