fix(server): fall back to a UTF-8 locale in terminal spawn env - #4827
fix(server): fall back to a UTF-8 locale in terminal spawn env#4827Kaidstor wants to merge 1 commit into
Conversation
GUI apps launched from the macOS Dock/Finder inherit no LANG/LC_* from launchd, so the integrated terminal's PTY shell starts in the single-byte C locale and zsh's line editor renders multibyte input (any non-ASCII text) as raw bytes like `<0080>`. Default LANG to en_US.UTF-8 on macOS and C.UTF-8 on Linux when neither LANG nor LC_ALL is present; explicitly configured locales and runtime env overrides stay untouched.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Approved 83d4050 Straightforward bug fix that adds a UTF-8 locale fallback for terminal spawning when no locale is configured. The change is defensive, respects existing user settings, and includes test coverage for both the fallback and preservation behaviors. You can customize Macroscope's approvability policy. Learn more. |
What Changed
The terminal manager now falls back to a UTF-8 locale when spawning a PTY whose environment defines neither
LANGnorLC_ALL:en_US.UTF-8on macOS,C.UTF-8on Linux (the only one guaranteed to exist), nothing on Windows. An explicitly configured locale — even a non-UTF-8 one — and per-session runtime env overrides are left untouched. Two tests cover the fallback and the "explicit locale wins" case.Why
GUI apps launched from the macOS Dock/Finder get no
LANG/LC_*from launchd (Terminal.app and iTerm inject their own; the integrated terminal inherits the server process env instead). The PTY shell therefore starts in the single-byte C locale, and zsh's line editor mangles any multibyte input — typing non-ASCII text (e.g. Cyrillic) renders as raw bytes instead of characters:Repro on macOS: launch the packaged app from the Dock, open the integrated terminal, run
locale→LANG="",LC_CTYPE="C"; then type any non-ASCII character.VS Code works around the same launchd behavior with
terminal.integrated.detectLocale; this is the minimal equivalent.Checklist
Note
Low Risk
Localized change to PTY spawn environment with conservative defaults and no override when the user already set locale variables.
Overview
Fixes integrated terminals starting in the C locale when the server inherits a bare environment (e.g. macOS Dock/Finder via launchd), which broke multibyte shell input.
createTerminalSpawnEnvnow runswithUtf8LocaleFallbackafter AppImage scrubbing: if neitherLANGnorLC_ALLis set, it setsLANGtoen_US.UTF-8on macOS andC.UTF-8on Linux; Windows is unchanged. ExistingLANG/LC_ALLvalues (including non-UTF-8 locales) are not overridden.Tests assert the macOS fallback and that an explicit
LANGis preserved.Reviewed by Cursor Bugbot for commit 83d4050. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fall back to a UTF-8 locale in terminal spawn env on non-Windows platforms
Introduces
withUtf8LocaleFallbackin Manager.ts to inject aLANGfallback whenLC_ALLandLANGare absent from the spawn environment. On macOS the fallback isen_US.UTF-8; on other non-Windows platforms it isC.UTF-8. Windows and envs with an explicit locale are left unchanged.createTerminalSpawnEnvnow accepts aplatformargument and pipes the env through this fallback after stripping AppImage variables.Macroscope summarized 83d4050.