fix: keep bounded text truncation UTF-16 safe#101654
Conversation
Co-authored-by: wm0018 <[email protected]> Co-authored-by: 廖石荣 0668000909 <[email protected]> Co-authored-by: 0668000787 <[email protected]>
|
Land-ready at exact head What changed:
Proof:
Before/after: before, a raw UTF-16 cutoff could end bounded output with a lone high surrogate; after, the helper backs off one code unit only for that boundary. Short text, ASCII text, limits, and suffixes are unchanged. Known proof gaps: none for the touched behavior. No configuration, persistence, public API, or protocol surface changed. |
|
Merged via squash.
|
|
Hi @steipete, thanks for consolidating the UTF-16 truncation fixes into this PR! I noticed there are two locations from my batch that aren't covered by #101654:
These two files are not in the 21 files touched by this PR. Could you take a look and include them as well, or let me know if there's a reason they should be handled separately? Happy to adjust either PR if changes are needed. |
* fix: keep bounded text UTF-16 safe Co-authored-by: wm0018 <[email protected]> Co-authored-by: 廖石荣 0668000909 <[email protected]> Co-authored-by: 0668000787 <[email protected]> * chore: keep UTF-16 release note in PR body --------- Co-authored-by: wm0018 <[email protected]> Co-authored-by: 廖石荣 0668000909 <[email protected]> Co-authored-by: 0668000787 <[email protected]>
* fix: keep bounded text UTF-16 safe Co-authored-by: wm0018 <[email protected]> Co-authored-by: 廖石荣 0668000909 <[email protected]> Co-authored-by: 0668000787 <[email protected]> * chore: keep UTF-16 release note in PR body --------- Co-authored-by: wm0018 <[email protected]> Co-authored-by: 廖石荣 0668000909 <[email protected]> Co-authored-by: 0668000787 <[email protected]>
What Problem This Solves
Several bounded CLI, diagnostics, logging, push, plugin, and memory surfaces truncate text by raw UTF-16 code-unit index. A limit can therefore split a surrogate pair and emit a lone surrogate, producing malformed text at transport and display boundaries.
This consolidates the useful fixes from #101605, #101606, #101609, #101612, #101613, #101614, #101616, #101619, #101622, #101623, #101625, #101628, #101631, and #101633. #101615 closed independently during review.
Why This Change Was Made
All affected callers now use the existing canonical
truncateUtf16Safehelper while preserving their current UTF-16 code-unit limits and output shapes. The patch removes one-off truncation proposals, keeps ownership at each caller, and adds caller-level regression tests instead of helper-only coverage.Contributor credit is preserved in the commit metadata and this PR body for @lsr911, @maweibin, and @wm0018. Release-note context stays here because
CHANGELOG.mdis release-owned.User Impact
Bounded text no longer ends with a lone surrogate when the cutoff lands inside an emoji or other supplementary-plane character. ASCII and already-short text remain unchanged, and every existing numeric cap retains its UTF-16 code-unit semantics.
Evidence
tbx_01kwy7jsz75zc8zwr6bw4kfx24: 8 focused Vitest shards, 862 tests passed.pnpm check:changedpassed, including core/extension typechecks, lint, import-cycle and DB guards.git diff --checkpassed.Supersedes #101622 and the overlapping UTF-16 truncation PRs listed above.