Repository navigation
fix(dsh-weknora): avoid splitting UTF-16 surrogate pairs in clip() (fixes #5519) - #5707
Open
Crazy-ChenMiLin wants to merge 1 commit into
Open
Crazy-ChenMiLin wants to merge 1 commit into
Crazy-ChenMiLin wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Description
Fixes #5519.
When
clip()inpackages/dsh-weknora/src/render.tstruncates text tomaxCharsusingnormalized.slice(0, maxChars), slicing between the two code units of a UTF-16 surrogate pair (such as emojis or mathematical italic symbols extracted from documents) leaves a lone high surrogate at the end of the string.When serialized to JSON in session history (
\ud835), model API gateways reject the malformed surrogate pair with 400 Bad Request, permanently breaking the client session.This change inspects whether
normalized.charCodeAt(end - 1)falls in the high-surrogate range[0xD800, 0xDBFF]. If so, it decrementsendby 1 before slicing so the surrogate pair is never split into a lone high surrogate.Type of Change
Verification
packages/dsh-weknora/test/render.test.mjsverifying that astral characters (mathematical italic symbols, emojis) are not split across surrogate boundaries and JSON parsing / round-trip remains valid.node --test "test/*.test.mjs": all 65 unit tests passed cleanly.git diff --check origin/main...HEADis clean.Checklist