Repository navigation
Reject non-ASCII Unicode digits in numeric barcodes - #275
Open
amalsaidov wants to merge 1 commit into
Open
amalsaidov wants to merge 1 commit into
amalsaidov wants to merge 1 commit into
Conversation
str.isdigit() returns True for non-ASCII characters such as superscript two (U+00B2) or the Arabic-Indic digits (U+0660..U+0669), so the EAN, UPC, ITF and PZN input validation accepted them. These then either crashed with a raw ValueError when int() rejected the character, or were silently encoded into a corrupt barcode whose string form contained non-ASCII characters. Require the input to be ASCII as well as numeric so these are rejected consistently with the documented IllegalCharacterError.
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.
Problem
str.isdigit()returnsTruefor many non-ASCII characters, e.g. superscript two (², U+00B2) and the Arabic-Indic digits (٠–٩, U+0660–U+0669). The numeric barcode classes validate their input with a bare.isdigit()check, so these characters pass validation and then:ValueErrorwhenint()later rejects the character (superscripts/circled digits), instead of the documentedIllegalCharacterError; orstr()form contains non-ASCII characters (Arabic-Indic digits, whichint()happens to accept).The same pattern affects EAN-13/8/14, UPC-A, ITF and PZN.
Fix
Require the input to be ASCII in addition to numeric in each validator, so non-ASCII digits are rejected consistently with the documented
IllegalCharacterError.Tests
Added a parametrized regression test (
test_non_ascii_digits_rejected) covering EAN-13/8/14, UPC-A, ITF and PZN with both a superscript digit and an Arabic-Indic digit. The test fails onmain(rawValueErroror no error) and passes with the fix. Full suite green,ruffclean.