fix(tui): force UTF-8 output when reading clipboard via PowerShell - #54057
fix(tui): force UTF-8 output when reading clipboard via PowerShell#54057Bartok9 wants to merge 1 commit into
Conversation
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Fixes CJK/emoji clipboard paste on Windows by forcing PowerShell to output UTF-8 via [Console]::OutputEncoding = [System.Text.Encoding]::UTF8. Without this, PowerShell emits the system ANSI code page (e.g. CP936 on Chinese Windows) and non-ASCII chars are decoded as ?. Clean one-line fix with a dedicated CJK regression test.
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: LGTM
Forces UTF-8 output encoding when reading clipboard via PowerShell on Windows. Fixes CJK/emoji paste bug where non-ASCII chars were decoded as ? because PowerShell emitted ANSI code page.
Changes
ui-tui/src/lib/clipboard.ts: Prepends[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;to Get-Clipboard commandui-tui/src/__tests__/clipboard.test.ts: Updated existing tests + 1 new CJK-specific test
Looks Good
- Mirrors the base64+UTF8.GetString approach already used on the write path
- Existing tests updated to match new command format
- Dedicated CJK test verifies the exact regression scenario
(Note: prior COMMENT review from tonydwb exists; this is a new review.)
Reviewed by Hermes Agent
|
Thanks for the focused Windows/WSL clipboard fix. Current The updated assertions in Automated hermes-sweeper review. |
Closes #53963.
Root Cause
Symptom — Pasting Chinese/CJK (or emoji, accented, Cyrillic) text into the Web Dashboard / Desktop app on Windows/WSL produces literal
?per character. Example:你好世界,测试中文→????????????. Affects all non-ASCII text on non-UTF-8 Windows locales.Root cause —
ui-tui/src/lib/clipboard.tsreads the clipboard withpowershell(.exe) -NoProfile -NonInteractive -Command Get-Clipboard -Raw. PowerShell writes that stdout using the system ANSI code page (e.g. CP936 on Chinese Windows), not UTF-8. Hermes then reads the child process stdout withencoding: 'utf8', so ANSI-coded bytes that aren't valid UTF-8 get replaced with?/ U+FFFD.Evidence —
POWERSHELL_ARGSatclipboard.ts:6. Notably the write path in the same file already solved the identical encoding problem (base64 +[System.Text.Encoding]::UTF8.GetString(...)forSet-Clipboard), but the read path was never given the matching treatment. New regression test feeds你好世界,测试中文through a mockedrunand asserts the emitted command carries the UTF-8 directive; it fails on currentmain.Fix + why this level — Prepend
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;to theGet-Clipboard -Rawcommand so PowerShell emits UTF-8 stdout, which then matches theencoding: 'utf8'read. This is the correct layer: fixing the producer's output encoding removes the mismatch at the source, rather than guessing the ANSI code page on the Node side (which varies by locale and is unreliable). It mirrors the existing write-path solution for symmetry.Scope / risk — Single constant change in
clipboard.ts(shared by both thewin32and WSLpowershell.exeread attempts). ASCII-only clipboards are unaffected (UTF-8 is a superset of ASCII). No change to the macOS/Wayland/X11 backends or the write path.Verification
npx vitest run src/__tests__/clipboard.test.ts(inui-tui/) — 20 passedforces UTF-8 output encoding in the PowerShell read command (CJK fix), which round-trips你好世界,测试中文and asserts the command contains[System.Text.Encoding]::UTF8. It FAILS onmain(3 tests fail without the fix) and passes with it.Real behavior proof
New + updated tests on this branch (after fix):
On
origin/main(source reverted, tests kept):Related