Skip to content

fix(win): search the last Path entry in get_shell_path - #1013

Open
kana001-bit wants to merge 1 commit into
microsoft:mainfrom
kana001-bit:fix/win-get-shell-path-last-path-entry
Open

kana001-bit wants to merge 1 commit into
microsoft:mainfrom
kana001-bit:fix/win-get-shell-path-last-path-entry

Conversation

@kana001-bit

Copy link
Copy Markdown

On Windows, a bare shell name such as cmd.exe is not found when its directory is the last entry in Path and Path does not end with ;. Spawning then fails with File not found: .

Reported by Roberto Bandini (@robertobandini) in #1006 (comment)

Cause

path_util::get_shell_path splits Path on ;, but only keeps an entry once it finds the ; after it. The text after the last ; is never added, so the last directory is never searched:

while ((pos = buffer.find(delimiter)) != std::wstring::npos) {
  paths.push_back(buffer.substr(0, pos));
  buffer.erase(0, pos + delimiter.length());
}
// what is left in `buffer` (the last entry) is dropped
Path Result
C:\NonExistent;C:\Windows\System32 File not found:
C:\NonExistent;C:\Windows\System32; OK
C:\Windows\System32;C:\NonExistent OK

Fix

After the loop, add what is left in buffer when it is not empty.

Tests

Added a Path lookup test to windowsTerminal.test.ts that sets Path to C:\NonExistent;%windir%\System32 (no trailing ;), spawns cmd.exe, and restores Path. It fails with File not found: before the fix and passes after it, with useConptyDll both false and true. All 34 Windows tests pass and lint is clean.

This is independent of #1006 (a different branch of the same function); the two PRs touch different lines.

🤖 Generated with Claude Code

The loop that splits Path on ';' only kept entries followed by a
delimiter, so the last directory was never searched when Path did not
end with ';'. Spawning "cmd.exe" with Path set to
"C:\NonExistent;C:\Windows\System32" failed with "File not found: ".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant