fix(shell_hooks): use explicit UTF-8 encoding with errors='replace' - #64374
fix(shell_hooks): use explicit UTF-8 encoding with errors='replace'#64374seasonmsg wants to merge 1 commit into
Conversation
Replace text=True (which uses locale encoding on Windows, e.g. GBK) with explicit encoding='utf-8', errors='replace' to prevent UnicodeDecodeError when shell hooks output non-ASCII characters. text=True on Windows defaults to the system's ANSI codepage (e.g. GBK/CP936 on Chinese Windows), causing silent failures when hook output contains characters outside that codepage.
|
Thanks for targeting the shared shell-hook subprocess bridge. The reported call remains on current main at Problems
Suggested changes
Automated hermes-sweeper review. |
|
Closing as resolved by PR #70875 (merged, commit 0f732cb), which closed out this bug class codebase-wide: every |
Problem
On Windows,
text=Trueinsubprocess.run()defaults to the system's ANSI codepage (e.g., GBK/CP936 on Chinese Windows). When shell hook scripts output characters outside this codepage,subprocess.runraisesUnicodeDecodeError, causing the hook to silently fail.Fix
Replace
text=Truewith explicitencoding='utf-8', errors='replace'in_spawn()(shell_hooks.py:467).encoding='utf-8': consistent cross-platform behaviorerrors='replace': graceful degradation instead of crash on invalid bytesBefore/After
Testing
_spawn()no longer crashes on non-ASCII hook output on Windows (Chinese locale)encoding='utf-8'+errors='replace'is a superset oftext=Truebehavior on UTF-8 systems