Skip to content

TUI selection copy mojibakes UTF-8 text on WSL (clip.exe fallback decodes stdin as the ANSI code page) #1245

Backlog

Description

@professional-slacker

Version / branch / commit

zero 0.14.0 (official linux-x64 release binary, ~/.local/bin/zero)

OS and environment

  • WSL2 (Ubuntu 26.04) on Windows 11 Home, Japanese locale — system ANSI code page is CP932
  • Terminal: Windows Terminal and herdr panes (reproduces in both, so it is not terminal-specific)
  • No Linux clipboard utility installed: wl-copy, xclip, xsel are all absent (the default for a stock WSL Ubuntu image)
  • clip.exe and powershell.exe are reachable through the default WSL interop PATH

Steps to reproduce

  1. Start the TUI (zero) on WSL2 with the environment above.
  2. Have the assistant produce Japanese text in the transcript, e.g. 文字化けチェック:日本語の表示テスト.
  3. Select that text with the mouse (the auto-copy-on-select path).
  4. Paste from the clipboard anywhere (a Windows app or another terminal).

A reproduction that bypasses Zero entirely and produces the same clipboard content:

$ printf '文字化けチェック' | clip.exe
# paste anywhere -> 譁・ュ怜喧縺代メ繧ァ繝・け

Expected behavior

The clipboard contains the same text that was displayed and selected: 文字化けチェック.

Actual behavior

The clipboard contains CP932 mojibake: 譁・ュ怜喧縺代メ繧ァ繝・け. The terminal display is unaffected — only the copied content is corrupted. The corruption is exactly "UTF-8 bytes reinterpreted as CP932": re-encoding the pasted mojibake as CP932 and decoding the result as UTF-8 restores the original text, and the identical string can be produced with the bare printf ... | clip.exe above.

Root cause chain (v0.14.0 source)

  1. internal/tui/transcript_selection.go → copyTranscriptSelectionCmd calls clipboard.WriteAll (github.com/atotto/clipboard v0.1.4).
  2. atotto/clipboard's unix init() (clipboard_unix.go) falls back to clip.exe when wl-copy, xclip, and xsel are all absent — the stock-WSL default unless the user apt-installed one of them.
  3. writeAll pipes the Go string bytes (UTF-8) straight into clip.exe's stdin.
  4. clip.exe decodes its stdin using the system ANSI code page — CP932 on Japanese Windows — so the UTF-8 payload is mojibaked before it reaches the Windows clipboard.
  5. clip.exe exits 0, so WriteAll reports success and the OSC52 fallback in copyTranscriptSelectionCmd never engages.

Impact is not Japanese-only: any Windows locale whose ANSI code page cannot represent UTF-8 (all of them, unless the beta "UTF-8 worldwide language support" switch is enabled) corrupts non-ASCII text through this path the same way.

Suggested fix direction

On WSL (detect via WSL_DISTRO_NAME or /proc/version), route the copy through powershell.exe with the payload base64-encoded inside an -EncodedCommand + Set-Clipboard script, so no non-ASCII byte ever crosses the process boundary and the system code page cannot corrupt the text. Keep the current atotto/clipboard → OSC52 chain as the fallback when powershell.exe is unreachable (e.g. interop disabled or a containerized WSL), so behavior elsewhere is unchanged.

Workaround available to affected users today: sudo apt install wl-clipboard (or xclip) makes atotto/clipboard use the Linux utility instead of clip.exe, and the mojibake disappears.

Happy to implement the fix if the issue is approved.

Activity

  1. added
    bug
    issue-approved
    on Nov 28, 2026
  2. Vasanthdev2004 commented on Nov 28, 2026

    @Vasanthdev2004
    Collaborator

    Thanks for the report, the cause chain made this quick to check.

    Confirmed from the source on main: the selection copy goes through clipboard.WriteAll, and with wl-copy, xclip, xsel and the Termux tools all missing the library settles on clip.exe for writing, which is what a stock WSL image gives it. I have not reproduced the paste myself, I have no machine with a CP932 code page, but your printf ... | clip.exe line shows the same result without Zero involved, and that is enough for me.

    Labelled bug and issue-approved. #1247 is the fix and is in review.

    One thing outside this issue, in case you see it next: pasting goes the other way through powershell.exe Get-Clipboard on the same setup, and its output is decoded on the way back. If Japanese text pasted into the TUI comes out wrong, please open a separate issue for it.

  3. professional-slacker commented on Nov 28, 2026

    @professional-slacker
    Author

    @Vasanthdev2004
    Thanks for looking into this!
    I tested the reverse direction as well, and it works fine in my environment.
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugissue-approved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions