Repository navigation
Fix card_number accepting non-ASCII decimal digits - #596
adityajai119 wants to merge 1 commit into
Conversation
mjanthony819
left a comment
There was a problem hiding this comment.
Verified locally against this branch (cc49ecb): tests/test_card.py (130 tests) and the card.py doctests (9) both pass, and the behavior change matches the intent.
On master, int() accepts any Unicode decimal digit, so transliterations of Luhn-valid numbers pass: "٤٢٤٢٤٢٤٢٤٢٤٢٤٢٤٢" (Arabic-Indic), "424242424242" (fullwidth), and "४२४२४२४२४२४२४२" (Devanagari) all return True, including mixed-script values like "4242٤٢٤٢424242". On this branch all of them are rejected while plain ASCII "4242424242424242" still passes. Non-string input degrades the same way on both branches (the decorator wraps the exception into a ValidationError; only the reason string changes), and bytes input behaves identically to master.
One completeness note, not a request to expand this PR: the same list(map(int, value)) pattern exists in src/validators/i18n/ru.py (ru_inn), and it has the same hole on master - ru_inn("٧٧٠٧٠٨٣٨٩٣"), the Arabic-Indic transliteration of the valid INN 7707083893, returns True. The other i18n validators I checked are safe: fi_business_id gates on an ASCII-only [0-9] regex and the es_* validators already call .isascii() on the digit body. ru_inn may be worth the same one-line guard in a follow-up.
AI assistance covered the analysis and this review text.
Summary
card_number()converted each character withint(), which accepts Unicode decimal digits. A card number written with Arabic-Indic or fullwidth digits therefore passed the Luhn check and was reported as valid.The fix adds an ASCII guard before character conversion.
Verification
tests/test_card.py;ruff checkclean.