fix(tool): respected windows lc locale env

Treat inherited LC_* category locale variables as ownership of the locale group before adding LANG or LC_ALL defaults.

Fixes #2701
This commit is contained in:
roboomp
2026-06-15 21:38:32 +00:00
parent 6ad2b0cd2f
commit 7dda4441e1
2 changed files with 18 additions and 0 deletions
@@ -74,11 +74,22 @@ function hasEnvValue(
return false;
}
function hasLocaleEnvValue(env: Record<string, string | undefined> | undefined, platform: NodeJS.Platform): boolean {
if (!env) return false;
for (const [key, value] of Object.entries(env)) {
if (value === undefined) continue;
const normalizedKey = platform === "win32" ? key.toUpperCase() : key;
if (normalizedKey === "LANG" || normalizedKey.startsWith("LC_")) return true;
}
return false;
}
function hasEnvGroupValue(
env: Record<string, string | undefined> | undefined,
group: ReadonlyArray<readonly [key: string, value: string]>,
platform: NodeJS.Platform,
): boolean {
if (group.some(([key]) => key === "LC_ALL") && hasLocaleEnvValue(env, platform)) return true;
for (const [key] of group) {
if (hasEnvValue(env, key, platform)) return true;
}
@@ -29,6 +29,13 @@ describe("buildNonInteractiveEnv", () => {
expect(env.LC_ALL).toBe("en_US.UTF-8");
});
it("preserves inherited Windows LC category locales as user-owned", () => {
const env = buildNonInteractiveEnv(undefined, { LC_CTYPE: "en_US.UTF-8" }, "win32");
expect(env.LANG).toBeUndefined();
expect(env.LC_ALL).toBeUndefined();
});
it("does not force UTF-8 encoding defaults on non-Windows platforms", () => {
const env = buildNonInteractiveEnv(undefined, {}, "linux");