Skip to content

Commit 5981839

Browse files
committed
fix(shared): clear mixed-case PATH keys in shell patches
1 parent 6da298e commit 5981839

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎packages/shared/src/shell.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,5 +1076,9 @@ describe("desktop shell environment updates", () => {
10761076
};
10771077
applyShellEnvironment(env, message.environment);
10781078
expect(env).toEqual({ PATH: "C:\\fresh", SSH_AUTH_SOCK: "/current.sock", UNRELATED: "keep" });
1079+
env.Path = "C:\\stale";
1080+
env.path = "C:\\other";
1081+
applyShellEnvironment(env, { PATH: null, SSH_AUTH_SOCK: null });
1082+
expect(env).toEqual({ UNRELATED: "keep" });
10791083
});
10801084
});

‎packages/shared/src/shell.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,13 +909,13 @@ function resolveKnownWindowsCliDirs(env: NodeJS.ProcessEnv): ReadonlyArray<strin
909909
}
910910

911911
/** Keep one PATH spelling in copied Windows environment records. */
912-
export function setWindowsPath(env: NodeJS.ProcessEnv, value: string): void {
912+
export function setWindowsPath(env: NodeJS.ProcessEnv, value: string | null): void {
913913
for (const key of Object.keys(env)) {
914914
if (key.toUpperCase() === "PATH") {
915915
delete env[key];
916916
}
917917
}
918-
env.PATH = value;
918+
if (value !== null) env.PATH = value;
919919
}
920920

921921
function mergeWindowsEnv(
@@ -969,8 +969,8 @@ export const resolveWindowsEnvironment = Effect.fn("shell.resolveWindowsEnvironm
969969

970970
export function applyShellEnvironment(env: NodeJS.ProcessEnv, patch: ShellEnvironmentPatch): void {
971971
for (const [key, value] of Object.entries(patch)) {
972-
if (value === null) delete env[key];
973-
else if (key === "PATH") setWindowsPath(env, value);
972+
if (key === "PATH") setWindowsPath(env, value);
973+
else if (value === null) delete env[key];
974974
else env[key] = value;
975975
}
976976
}

0 commit comments

Comments
 (0)