Skip to content

Commit dee3e06

Browse files
committed
fix(desktop): preserve inherited locale precedence
1 parent d5a5828 commit dee3e06

2 files changed

Lines changed: 40 additions & 9 deletions

File tree

‎apps/desktop/src/shell/DesktopShellEnvironment.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,29 @@ describe("DesktopShellEnvironment", () => {
195195
}),
196196
);
197197

198+
it.effect("does not mix login-shell locale categories into an inherited locale", () =>
199+
Effect.gen(function* () {
200+
const env: NodeJS.ProcessEnv = {
201+
SHELL: "/bin/zsh",
202+
PATH: "/usr/bin",
203+
LANG: "en_US.UTF-8",
204+
};
205+
206+
yield* runShellEnvironment({
207+
env,
208+
platform: "darwin",
209+
handler: () =>
210+
envOutput({
211+
PATH: "/opt/homebrew/bin:/usr/bin",
212+
LC_ALL: "de_DE.UTF-8",
213+
}),
214+
});
215+
216+
assert.equal(env.LANG, "en_US.UTF-8");
217+
assert.equal(env.LC_ALL, undefined);
218+
}),
219+
);
220+
198221
it.effect("falls back to a UTF-8 LC_CTYPE when no locale is available on macOS", () =>
199222
Effect.gen(function* () {
200223
const env: NodeJS.ProcessEnv = {

‎apps/desktop/src/shell/DesktopShellEnvironment.ts‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,6 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
467467
"HOMEBREW_PREFIX",
468468
"HOMEBREW_CELLAR",
469469
"HOMEBREW_REPOSITORY",
470-
"LANG",
471-
"LC_ALL",
472-
"LC_CTYPE",
473470
"XDG_CONFIG_HOME",
474471
"XDG_DATA_HOME",
475472
"XDG_RUNTIME_DIR",
@@ -480,16 +477,27 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
480477
}
481478
}
482479

483-
// GUI launches inherit no locale from launchd, so spawned agents land in the C
484-
// locale and pbcopy decodes their UTF-8 output as MacRoman. Older supported
485-
// macOS releases do not provide C.UTF-8, so set only LC_CTYPE to a UTF-8 locale
486-
// available on those releases. Leaving LANG unset keeps C-stable collation and
487-
// formatting, so output parsing is unaffected.
480+
// Locale variables form one precedence group: LC_ALL can override an inherited
481+
// LANG or LC_CTYPE, so only hydrate the group when the process has none of them.
488482
if (
489483
config.platform === "darwin" &&
490484
LOCALE_ENV_NAMES.every((name) => Option.isNone(trimNonEmpty(config.env[name])))
491485
) {
492-
config.env.LC_CTYPE = FALLBACK_LC_CTYPE;
486+
for (const name of LOCALE_ENV_NAMES) {
487+
const value = trimNonEmpty(shellEnvironment[name]);
488+
if (Option.isSome(value)) {
489+
config.env[name] = value.value;
490+
}
491+
}
492+
493+
// GUI launches inherit no locale from launchd, so spawned agents land in the C
494+
// locale and pbcopy decodes their UTF-8 output as MacRoman. Older supported
495+
// macOS releases do not provide C.UTF-8, so set only LC_CTYPE to a UTF-8 locale
496+
// available on those releases. Leaving LANG unset keeps C-stable collation and
497+
// formatting, so output parsing is unaffected.
498+
if (LOCALE_ENV_NAMES.every((name) => Option.isNone(trimNonEmpty(config.env[name])))) {
499+
config.env.LC_CTYPE = FALLBACK_LC_CTYPE;
500+
}
493501
}
494502

495503
if (

0 commit comments

Comments
 (0)