fix(tui): preserve UTF-8 in PowerShell clipboard writes (CJK/emoji)#35222
Merged
Conversation
…erve UTF-8 When writing text to the clipboard via PowerShell (WSL2 and native Windows), the previous implementation piped text through stdin using `Set-Clipboard -Value $input`. PowerShell reads stdin using the Windows system's default ANSI code page (e.g. CP936 for Chinese Windows), causing all non-ASCII characters (CJK, emoji, accented) to become garbled. Fix: encode the text as base64 in Node.js and pass it as a command argument. PowerShell decodes it from base64 using explicit UTF-8, bypassing the code page issue entirely. Fixes #35107
The per-entry psScript callback was identical for every PowerShell entry, so the function-valued union member added structure without behavior. Collapse WriteCmd to a plain stdin boolean and apply the one shared base64 script in the write loop. Document the CP936 root cause inline. Co-authored-by: BROCCOLO1D <279959838+BROCCOLO1D@users.noreply.github.com>
Contributor
🔎 Lint report:
|
1 task
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.
Summary
/copynow preserves CJK, emoji, and accented text in WSL2 and native Windows. Previously the TUI piped UTF-8 bytes topowershell.exe Set-Clipboard -Value $input, but PowerShell decodes piped stdin with the system ANSI code page (CP936 on Chinese Windows), not UTF-8 — so你好世界became浣犲ソ涓栫晫.Fixes #35107.
Changes
ui-tui/src/lib/clipboard.ts: PowerShell write paths (win32 + WSL) base64-encode the UTF-8 bytes and pass them as a-Commandargument, decoding with[System.Text.Encoding]::UTF8.GetString(...). This removes the stdin-encoding variable entirely (also immune to BOM injection on redirect). All other backends (pbcopy, wl-copy, xclip, xsel) keep reading UTF-8 stdin natively via astdinflag.Validation
你好世界,测试中文 🎉 cafécopied in WSL2浣犲ソ涓栫晫锛屾祴璇曚腑鏂…你好世界,测试中文 🎉 caféE2E: base64 round-trip recovers the exact original; decoding the same UTF-8 bytes as CP936 reproduces the issue's reported garble.
clipboard.test.ts19/19 pass;src/lib/clipboard.tstype-checks clean (the 18 pre-existingexecFileNoThrow.tstype errors are unrelated and present onmain).Credit
Salvaged from #35124 (@annguyenNous — base64-via-argument mechanism, authorship preserved) with the duplicate #35122 (@BROCCOLO1D — first to report + UTF-8 console-encoding approach) co-credited. Follow-up commit collapses the per-entry
psScriptcallback to a shared script +stdinflag.Known sibling (not in scope)
The read path (
Get-Clipboard -Raw→ Node reads stdout as utf8) has the symmetric encoding gap in the Windows→TUI direction. The issue is write-only; read needs a different mechanism (can't base64 stdout without wrapping) and is left for a follow-up.Infographic