fix(regex): keep U+2028/U+2029 in Byte segments when Kanji mode is on - #413
Open
maximilliangrand wants to merge 1 commit into
Open
fix(regex): keep U+2028/U+2029 in Byte segments when Kanji mode is on#413maximilliangrand wants to merge 1 commit into
maximilliangrand wants to merge 1 commit into
Conversation
The Byte-mode regex matches characters with (?:.|[\r\n]). In JS a dot does not match any of the four line terminators (\n, \r, U+2028, U+2029), and only \n and \r were added back. With Kanji mode enabled this regex is used for Byte segments, so a U+2028 or U+2029 in the input matched no segment regex at all and was silently dropped, corrupting the encoded data. Add the two missing separators to the class. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Bug
With Kanji mode enabled (a
toSJISFuncsupplied), aU+2028(LINE SEPARATOR) orU+2029(PARAGRAPH SEPARATOR) in the input is silently dropped, so the encoded QR decodes to different data than was passed in. No error is thrown.Cause
The Byte-mode matcher in
lib/core/regex.jsis built as(?:.|[\r\n]). In JavaScript,.(without thesflag) matches every code unit except the four line terminators\n,\r,U+2028,U+2029. Only\rand\nwere added back, soU+2028/U+2029match no segment regex at all (numeric/alphanumeric/kanji don't cover them either) and are dropped during segmentation.This
exports.BYTEregex is only used for Byte segments when Kanji mode is on (seelib/core/segments.js). The default path uses theBYTE_KANJInegated class ([^A-Z0-9 $%*+\-./:]+), which does match those code points, so default mode is unaffected.Fix
Add the two missing separators to the class:
Evidence
Added two
test/unit/core/segments.test.jscases mirroring the existing\ncase. They fail on master (not ok 25/not ok 26) and pass with the fix (26/26). InspectingQRCode.create().segmentsdirectly confirms the Byte segment retains theU+2028/U+2029bytes with the fix and drops them without it.