fix(shell): use byte length for preview truncation#29382
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Potential duplicates found:
These PRs are all targeting the same bug in shell preview truncation with multi-byte characters. PR #29372 appears to be the most direct duplicate as it fixes the exact same issue (#29291) with the same title. |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Fixes #29291. The preview() function used text.length (UTF-16 code units) to check if output exceeds the metadata limit, but truncation should be based on byte length. This caused incorrect truncation for multi-byte characters like CJK, emoji, etc. Additionally, text.slice(-MAX_METADATA_LENGTH) could split a surrogate pair. Use Buffer.byteLength for the check and Buffer-based truncation that respects UTF-8 continuation bytes, matching the existing tail() function pattern.