mirror of
https://github.com/rehan-remade/universal-modder.git
synced 2026-11-05 01:37:40 +00:00
[PR #276] [MERGED] Read tool output as UTF-8, not the locale codec (um win ps dies on CJK window titles) #275
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
rehan-remade/universal-modder#275
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/rehan-remade/universal-modder/pull/276
Author: @23318yy-afk
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @rehan-remade
Base:
main← Head:fix/utf8-tool-output📝 Commits (4)
9b4ad8dwin: read tool output as UTF-8, not the locale codeca47b3d1win: UTF-8 for scan's PowerShell and WinDrive too, console code page for taskkill/reg (review fixes)76b770drenormalize line endings to match .gitattributes (as on main since #304)1710669Merge remote-tracking branch 'origin/main' into land/pr-276📊 Changes
8 files changed (+152 additions, -34 deletions)
View changed files
➕
tests/test_encoding.py(+78 -0)📝
um/common.py(+32 -2)📝
um/kb.py(+4 -4)📝
um/ps1/WinDrive.ps1(+10 -5)📝
um/render3d.py(+2 -2)📝
um/scan.py(+4 -4)📝
um/video.py(+4 -4)📝
um/win.py(+18 -13)📄 Description
What broke
um win psdies on a Windows machine whose window titles aren't ASCII:um/win.py:powershell()calledsubprocess.run(..., text=True)with noencoding=, so Python decoded thepipe with
locale.getpreferredencoding(): cp936 on a Chinese Windows, cp1252 on a Western one.PowerShell 5.1 writes UTF-8 to a pipe — byte for byte:
ffmpeg does the same with the path it echoes, so a CJK game folder or save path takes
um videodown too:Linux CI is UTF-8 and never sees this, which is why it shipped.
The fix
um.common.text_utf8()— the one set of subprocess kwargs for reading a tool's text output:text=True, encoding="utf-8", errors="replace". Everysubprocess.run/Popeninum/that decodes atool's output now goes through it (20 call sites across 6 modules:
win,scan,video,render3d,kb,common).win.powershell()also asks PowerShell for UTF-8 ([Console]::OutputEncoding) so the bytes and thedecoder agree. The prefix is best-effort — a console-less process makes it throw, so it's wrapped.
errors="replace"means a codec we guessed wrong costs one replacement character instead of a tracebackin a reader thread.
Also: the
gfxcaptureself-check was lyingum win setupdecided with"gfxcapture" in outover the stdout of-h filter=gfxcapture. A build thatlacks the filter answers
Unknown filter 'gfxcapture'.— on stdout — which contains the name, so thecheck passed on exactly the builds it was meant to catch:
It now matches the name as a word in
-filters, which is a plain success/failure query:Tests
tests/test_encoding.py(new, cross-platform — it fails on Windows, not on the Ubuntu runner):PYTHONIOENCODING=cp1252on the host;subprocess.*call inum/may passtext=Truewithoutencoding=;um video probeon中文 测试.mp4.Verified
On Windows 11, cp936, Python 3.12.15 (
uv tool install):um win psUnicodeDecodeError: 'gbk' codec can't decode byte 0xafum video probe "中文 测试.mp4"{"duration": 3.0, "width": 640, ...}145 passed, 1 skipped(the cygpath/Git Bash one) onmain@5ba8150— rebased onto it, so the countincludes upstream's own suite, which grew while this branch was open. Plus
um kb check --index(PASS, 182 notes) and
um publish check .(0 failures) — the three steps this repo's CI runs.The AST guard in
tests/test_encoding.pyis the interesting one: it is what proves no call site inum/,upstream's new ones included, still decodes with the locale codec.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.