Merge pull request #2941 from xiaweiwei67-stack/fix/bash-tempfile-utf8

fix(bash): write large-output temp file as UTF-8
This commit is contained in:
zhayujie
2026-07-07 17:00:01 +08:00
committed by GitHub
2 changed files with 65 additions and 2 deletions

View File

@@ -202,8 +202,12 @@ SAFETY:
total_bytes = len(output.encode('utf-8'))
if total_bytes > DEFAULT_MAX_BYTES:
# Save full output to temp file
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.log', prefix='bash-') as f:
# Save full output to temp file. encoding='utf-8' is required:
# the default text-mode encoding is the platform locale (e.g.
# cp936/GBK on Chinese Windows), which raises UnicodeEncodeError
# for output containing emoji or other non-locale characters and
# would discard an otherwise successful command result.
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.log', prefix='bash-', encoding='utf-8') as f:
f.write(output)
temp_file_path = f.name