fix(tui): force UTF-8 output encoding in PowerShell clipboard read - #38090
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(tui): force UTF-8 output encoding in PowerShell clipboard read#38090liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
PowerShell defaults to the system ANSI code page for console output. On non-English Windows (e.g. CP936), this mangles emoji and CJK characters to '?' when piping Get-Clipboard output through stdout. Prefix the -Command script with [Console]::OutputEncoding assignment to UTF-8, matching the approach already used on the write path (which uses base64 encoding to bypass the same issue on stdin). Fixes NousResearch#38077
Contributor
|
Thanks for the focused fix. Current main still passes raw The regression assertions in Automated hermes-sweeper review. |
Contributor
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.
What does this PR do?
Forces UTF-8 output encoding in the PowerShell clipboard read command so that emoji and CJK characters are preserved instead of being mangled to
?on non-English Windows.Related Issue
Fixes #38077
Type of Change
Changes Made
ui-tui/src/lib/clipboard.ts: Prefix the-Commandscript with[Console]::OutputEncoding = [System.Text.Encoding]::UTF8beforeGet-Clipboard -Raw. Without this, PowerShell defaults to the system ANSI code page (e.g. CP936) and multi-byte characters are mangled to?when piped through stdout.ui-tui/src/__tests__/clipboard.test.ts: Updated existing Windows and WSL test assertions to match the new args. Added a dedicated regression test (sets UTF-8 output encoding on Windows to preserve emoji) that verifies the encoding prefix is present.How to Test
🎉 hello 🫶) to the clipboard.hermes --tuiand paste into the composer — the emoji should appear correctly, not as??.cd ui-tui && npx vitest run src/__tests__/clipboard.test.ts— all 20 tests should pass (including the newsets UTF-8 output encoding on Windows to preserve emojitest).Checklist
Code
fix(scope):,feat(scope):, etc.)npx vitest run src/__tests__/clipboard.test.tsand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
ui-tui/src/lib/clipboard.ts—POWERSHELL_ARGSconstant, used byreadClipboardCommands()(3 call sites: win32, WSL via WSL_INTEROP, WSL via WSL_DISTRO_NAME)_powershellWriteScript). This fix addresses the read path asymmetry.isUsableClipboardText()already handles null bytes and replacement characters as safety net.