Subprocess(fix[encoding]): Enforce UTF-8 decoding for tmux output#679
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #679 +/- ##
=======================================
Coverage 51.29% 51.29%
=======================================
Files 25 25
Lines 3488 3488
Branches 686 686
=======================================
Hits 1789 1789
Misses 1404 1404
Partials 295 295 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d510846 to
b9a0223
Compare
1 task
tony
commented
May 23, 2026
Member
Author
tony
left a comment
There was a problem hiding this comment.
Code review
No issues found. Checked for bugs and CLAUDE.md compliance.
🤖 Generated with Claude Code
17fb9b1 to
c85d4da
Compare
…tion why: The previous xfail depended on locale.getencoding(), which only exists on Python 3.11+ and skipped libtmux's supported Python 3.10 runtime. what: - Recreate the strict xfail regression test with a temporary LC_CTYPE=C boundary - Assert FORMAT_SEPARATOR survives list-sessions output before parse_output consumes it - Keep the test skipped only when Python UTF-8 mode masks locale decoding
why: tmux format output is UTF-8, but text=True without an explicit encoding lets CPython decode with the process locale and corrupts non-ASCII separators under non-UTF-8 locales. what: - Pass encoding="utf-8" to subprocess.Popen in tmux_cmd
why: ControlMode opens its own tmux -C subprocess with text=True, so it has the same locale-decoding risk as tmux_cmd but through a separate stdout surface. what: - Add a strict xfail regression test for non-ASCII control protocol output under LC_CTYPE=C - Drive display-message through the control client and assert FORMAT_SEPARATOR survives stdout decoding
why: ControlMode reads tmux control protocol output through its own text-mode subprocess, so locale decoding can corrupt or reject UTF-8 output under non-UTF-8 locales. what: - Pass encoding="utf-8" to the control-mode subprocess.Popen call
why: tmux_cmd and ControlMode now decode tmux output as UTF-8 explicitly, so the locale regression checks should fail only on future regressions. what: - Remove strict xfail markers from the tmux_cmd and ControlMode UTF-8 regression tests - Keep the UTF-8-mode skip that avoids masked locale-decoding behavior
why: Document the user-visible bug fix for the 0.58.x release. what: - Add Fixes entry for tmux_cmd encoding on non-UTF-8 locales
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
tmux_cmdusessubprocess.Popen(text=True)withoutencoding="utf-8", causing FORMAT_SEPARATOR (U+241E) corruption on non-UTF-8 localesencoding="utf-8"to thesubprocess.Popencall intmux_cmd.__init__Commit sequence (hermetic proof)
922a326alocale.getencoding→"latin-1", runslist-sessionsthroughtmux_cmd, asserts FORMAT_SEPARATOR survivesâ\x90\x9e, assertion fails at the right placee05c8ca0encoding="utf-8"insubprocess.Popen— zero test changesc8279acfRoot cause
Commit
1a5e69a2(2025-02-02) removedconsole_to_str()(which had an explicit UTF-8 fallback) and switched to baretext=True. Withoutencoding="utf-8", CPython'ssubprocess._text_encoding()falls back tolocale.getencoding(). On non-UTF-8 locales, the 3-byte UTF-8 sequence for␞(U+241E) is decoded as three latin-1 code points (â\x90\x9e), making.split(FORMAT_SEPARATOR)produce a single unsplit element. This cascades toparse_output()wherezip(..., strict=True)raisesValueError, and list accessors likeserver.sessionsreturn empty results.tmux has mandated UTF-8 since 2015 — hardcoding
encoding="utf-8"matches tmux's output contract.Fixes: #678
Related: tmux-python/tmuxp#1044
Test plan
uv run ruff check . --fix --show-fixes— passesuv run ruff format .— no changesuv run mypy— no issuesuv run pytest --reruns 0 -vvv— 1257 passed, 2 skippedjust build-docs— builds successfully