Skip to content

Commit d63a431

Browse files
committed
fix: return null from getShellFromEnv when environment variables are not set
- Modified getShellFromEnv() to return null instead of hardcoded fallback values when COMSPEC (Windows) or SHELL (Unix) environment variables are not set - This ensures the function accurately reflects whether the shell path was obtained from environment variables - Updated test comments to clarify the expected behavior with the fix - All existing tests continue to pass as the fallback logic is handled by getSafeFallbackShell() Fixes #8578
1 parent b011b63 commit d63a431

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/utils/__tests__/shell.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ describe("Shell Detection Tests", () => {
247247

248248
it("falls back to /bin/zsh if no config, userInfo, or env variable is set", () => {
249249
vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any
250+
// With the fix, getShellFromEnv() returns null when SHELL is not set,
251+
// so it falls back to the safe default from getSafeFallbackShell()
250252
expect(getShell()).toBe("/bin/zsh")
251253
})
252254
})
@@ -303,6 +305,8 @@ describe("Shell Detection Tests", () => {
303305

304306
it("falls back to /bin/bash if nothing is set", () => {
305307
vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any
308+
// With the fix, getShellFromEnv() returns null when SHELL is not set,
309+
// so it falls back to the safe default from getSafeFallbackShell()
306310
expect(getShell()).toBe("/bin/bash")
307311
})
308312
})
@@ -345,6 +349,8 @@ describe("Shell Detection Tests", () => {
345349
throw new Error("userInfo error")
346350
})
347351
delete process.env.SHELL
352+
// With the fix, getShellFromEnv() returns null when SHELL is not set,
353+
// so it falls back to the safe default from getSafeFallbackShell()
348354
expect(getShell()).toBe("/bin/bash")
349355
})
350356
})

src/utils/shell.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,14 @@ function getShellFromEnv(): string | null {
269269

270270
if (process.platform === "win32") {
271271
// On Windows, COMSPEC typically holds cmd.exe
272-
return env.COMSPEC || "C:\\Windows\\System32\\cmd.exe"
272+
return env.COMSPEC || null
273273
}
274274

275-
if (process.platform === "darwin") {
276-
// On macOS/Linux, SHELL is commonly the environment variable
277-
return env.SHELL || "/bin/zsh"
275+
// On Unix-like systems (macOS, Linux), SHELL is the environment variable
276+
if (process.platform === "darwin" || process.platform === "linux") {
277+
return env.SHELL || null
278278
}
279279

280-
if (process.platform === "linux") {
281-
// On Linux, SHELL is commonly the environment variable
282-
return env.SHELL || "/bin/bash"
283-
}
284280
return null
285281
}
286282

0 commit comments

Comments
 (0)