Repository navigation
Fix VS15 applying more than once to the same base character - #241
afonsojanu wants to merge 2 commits into
Conversation
VS16 clears last_measured_idx once it has adjusted the pending cluster width, specifically to stop a second VS16 from reapplying to the same base character. The VS15 branch right below it does the same kind of adjustment but never got that reset, so a base character followed by two VS15 selectors in a row gets narrowed twice instead of once, and three in a row narrows it three times. Since a wide character can only lose one column going from wide to narrow, every VS15 past the first one is quietly stealing a column that belongs to whatever comes next in the string. This affected width(), wcswidth(), and wcstwidth(), each of which carries its own copy of the VS15 handling. Added a test covering all three plus the case where a trailing character follows the repeated selectors, since that's where the corruption actually becomes visible downstream.
|
Thanks, I consider these "glitch unicode", they do not occur naturally in the wild except by a kind of In this case, the index is easy to update (its a one line change), and we're already in VS-15 branch conditional so it is not harmful for general performance. Note that VS-15 behavior is also contested, #234 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #241 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 1976 1979 +3
Branches 463 463
=========================================
+ Hits 1976 1979 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Looking more, this change is not conforming to any known unicode standard, an errant/extra vs15 or other combining character is already split or determined by grapheme clustering. This is only accepted because it is so small and otherwise harmless. |
Do not re-apply "narrowing" of a base character with repeated VS-15. Closes jquast#241. This change is not conforming to any known unicode standard, an errant/extra vs15 or other combining character is already split or determined by grapheme clustering. This is only accepted because it is so small and otherwise harmless. I consider these "glitch unicode", they do not occur naturally in the wild except by a kind of ``/dev/urandom`` (or fuzzing) of codepoints. This library generally takes a stance against trying to determine accurate measurements of "non-recommended sequences", especially if it hurts performance. In this case, the index is easy to update (its a one line change), and we're already in VS-15 branch conditional so it is not harmful for general performance. Note that VS-15 behavior is also contested, jquast#234 --------- Co-authored-by: Afonso Januário <[email protected]>
VS16 handling clears
last_measured_idxright after it adjusts the pendingcluster width, and the comment there says why: it stops a second VS16 from
reapplying to the same base character. The VS15 branch just below it does
the same kind of adjustment (narrowing a wide base character by one column)
but never got that same reset.
So a base character followed by two VS15 selectors in a row gets narrowed
twice, and three in a row narrows it three times, even though VS15 requests
are supposed to be idempotent, applying "text presentation" once, the same
way applying it twice shouldn't ask for anything different than applying it
once.
A wide character can only lose one column going from wide to narrow, so
every VS15 past the first is quietly stealing a column that belongs to
whatever follows it in the string, which is how this shows up in practice:
not as a standalone measurement being off, but as everything after a
malformed run of variation selectors drifting out of alignment.
This same handling is duplicated across
width(),wcswidth(), andwcstwidth(), and all three had the identical gap, so all three needed theone-line fix. I added a test exercising all three, including the case
where a trailing character follows the repeated selectors, since that's
where the lost column actually becomes visible.
Ran the full test suite locally (
pytest tests/) and it's green, 1263passed.