fix: use platform-aware UTF-8 locale fallback for PTY (#1137)

C.UTF-8 does not exist on macOS, causing the terminal to fall back
to ASCII encoding when LANG is unset. Use en_US.UTF-8 on macOS and
C.UTF-8 on Linux. Also set LC_CTYPE with the platform-appropriate
value (UTF-8 on macOS, C.UTF-8 on Linux) for additional safety.
This commit is contained in:
Wenqiang.Xu
2026-05-08 16:19:24 +03:00
committed by GitHub
parent 4b6fec774d
commit 3716deb16c
+5 -1
View File
@@ -121,6 +121,9 @@ export function createTerminalRuntime({
return resolved;
};
const utf8LocaleFallback = process.platform === 'darwin' ? 'en_US.UTF-8' : 'C.UTF-8';
const lcCtypeFallback = process.platform === 'darwin' ? 'UTF-8' : 'C.UTF-8';
const spawnTerminalPtyWithFallback = (pty, { cols, rows, cwd, env }) => {
const shellCandidates = getTerminalShellCandidates();
if (shellCandidates.length === 0) {
@@ -139,7 +142,8 @@ export function createTerminalRuntime({
...env,
TERM: 'xterm-256color',
COLORTERM: 'truecolor',
LANG: env.LANG || process.env.LANG || 'C.UTF-8',
LANG: env.LANG || process.env.LANG || utf8LocaleFallback,
LC_CTYPE: env.LC_CTYPE || process.env.LC_CTYPE || lcCtypeFallback,
},
};