diff options
| author | Mohamed Hegazy <8000722+mhegazy@users.noreply.github.com> | 2026-05-30 12:14:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-30 12:14:03 -0700 |
| commit | c7a3e2ffa047de2da799c2237475f024c83f4c4b (patch) | |
| tree | c68441cfe3ca7221df02c9373dd35835e097e16c /plugins/security-guidance/hooks/sg-python.sh | |
| parent | c40770ae5a1d6855fce096c5b747e709ec946b2b (diff) | |
| parent | 1ecf3d1bac6ca2be1fbedef9500ca1457da8d42d (diff) | |
Merge pull request #2100 from anthropics/fix-2099-text-true-pythonutf8
security-guidance: purge text=True from subprocess.run + bake PYTHONUTF8=1 (#2099)
Diffstat (limited to 'plugins/security-guidance/hooks/sg-python.sh')
| -rwxr-xr-x | plugins/security-guidance/hooks/sg-python.sh | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/plugins/security-guidance/hooks/sg-python.sh b/plugins/security-guidance/hooks/sg-python.sh index 67119105..9cf8cc07 100755 --- a/plugins/security-guidance/hooks/sg-python.sh +++ b/plugins/security-guidance/hooks/sg-python.sh @@ -22,6 +22,17 @@ # "${CLAUDE_PLUGIN_ROOT}/hooks/security_reminder_hook.py" set -e +# Force UTF-8 for ALL Python filesystem + IO operations (PEP 540). +# Without this, Windows Python defaults `locale.getpreferredencoding()` to +# cp1252 — which makes `text=True` in subprocess.run / open() / json.load +# crash the internal reader thread on any byte that's undefined in cp1252 +# (e.g. the 0x81 byte from ف, present in any path/filename with +# Arabic/Hebrew/CJK characters). See #2056, #2099. +# +# No-op on macOS/Linux (already UTF-8). Must be set BEFORE Python starts — +# changing it from inside the interpreter has no effect. +export PYTHONUTF8=1 + # Git Bash / MSYS on Windows hands script paths to this shim in POSIX form # (`/c/Users/...`). When we exec a Windows `python.exe` (which we do on # Windows since `python3` is the Microsoft Store stub), python interprets the |
