Replace .isdigit() with ASCII-only digit check#2722
Open
danfitz36 wants to merge 1 commit intoKozea:mainfrom
Open
Replace .isdigit() with ASCII-only digit check#2722danfitz36 wants to merge 1 commit intoKozea:mainfrom
danfitz36 wants to merge 1 commit intoKozea:mainfrom
Conversation
… hints Python's str.isdigit() returns True for non-ASCII digit characters (e.g. Arabic-Indic digits), but the HTML spec defines digits as ASCII digits only (0-9). Replace all .isdigit() calls in presentational hint parsing and PDF form field handling with an ASCII-only helper. Fixes Kozea#2721 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
|
Thanks for the pull request! We’ll merge #2721 first and see what we can do for this. I think that it may be better to include these changes in a larger fix that can handle min/max values from the HTML specification and checks input values more seriously. There’s no need to work more on this PR now, we’ll see after #2721. |
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.
Summary
is_ascii_digits()utility that only matches ASCII digits (0-9), unlike Python'sstr.isdigit()which also matches non-ASCII digit characters (e.g. Arabic-Indic٠١٢٣).isdigit()calls in presentational hint parsing (css/__init__.py) and PDF form field handling (pdf/anchors.py) with the new functioncellpadding,hspace,vspace,width,height,maxlengthContext
Python's
str.isdigit()returnsTruefor non-ASCII digit characters, but the HTML spec defines digits as ASCII digits only (0-9). This could cause incorrect unit appending (e.g. treating Arabic-Indic digits as a bare number and appendingpx).Note: the two
.isdigit()calls insvg/bounding_box.pyare intentionally left unchanged — they check individual characters in SVG path data, a different context.Related to #2636.
Test plan
is_ascii_digits: basic values, empty string, non-digits, non-ASCII digitsruff checkpassesFixes #2721