fix: avoid splitting surrogate pairs in trimEnd - #2423
Merged
Dmitriy Vasyura (dmitrivMS) merged 1 commit intoOct 5, 2026
Merged
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation matches the established trimMiddle approach and the regression test covers both boundary cases.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes trimEnd so truncation does not split UTF-16 surrogate pairs.
Changes:
- Adjusts truncation when the boundary intersects an astral character.
- Adds regression coverage for safe and unsafe truncation boundaries.
| File | Description |
|---|---|
src/common/stringUtils.ts |
Prevents retaining a lone high surrogate. |
src/common/stringUtils.test.ts |
Tests emoji truncation boundaries. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Dmitriy Vasyura (dmitrivMS)
approved these changes
Oct 5, 2026
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge
October 5, 2026 05:20
Martin Aeschlimann (aeschli)
approved these changes
Oct 5, 2026
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.
Root cause:
trimEndinsrc/common/stringUtils.tscuts the string atmaxLength - 1UTF-16 code units. When that cut lands between the two halves of a surrogate pair (an emoji or any other astral character), the result keeps a lone high surrogate before the ellipsis. Truncated object previews, keys, descriptions and console.table rows then show a replacement character. For exampletrimEnd('ab\u{1F600}cd', 4)returns'ab\uD83D…'.trimMiddle, right below it, already guards against this case, buttrimEnddid not.Fix: if the last kept code unit starts a surrogate pair, drop it too, using the same
codePointAt(...) >= 0x10000check thattrimMiddleuses.Test: added
trimEnd does not split surrogate pairstosrc/common/stringUtils.test.ts. It fails before the change (expected 'ab\uD83D…' to equal 'ab…') and passes after. The rest of the unit suite is unchanged.