Skip to content

fix: quote PowerShell paths containing special characters - #488

Closed
aaaxingiiiiiii wants to merge 1 commit into
microsoft:mainfrom
aaaxingiiiiiii:fix/pwsh-path-quoting
Closed

aaaxingiiiiiii wants to merge 1 commit into
microsoft:mainfrom
aaaxingiiiiiii:fix/pwsh-path-quoting

Conversation

@aaaxingiiiiiii

Copy link
Copy Markdown

Summary

Path suggestions in PowerShell (pwsh / powershell) were only quoted when they contained a space, and an embedded single quote was escaped as \', which is bash syntax. Accepting a folder suggestion could therefore insert a command that PowerShell parses differently:

Folder Inserted before What PowerShell does
a$b a$b/ expands $b as a variable
a&b a&b/ & is the call operator
it's it's/ starts an unterminated string
it's dir 'it\'s dir/' \ is not an escape character, so the string ends early

This change single-quotes the path when it contains whitespace or a character that is special in argument mode (' " ` $ & | ; , ( ) { } < >, or a leading @ or #), and writes embedded single quotes as ''. In PowerShell, single-quoted strings are literal (about_Quoting_Rules). Other shells are unchanged.

Test plan

  • Added src/tests/runtime/utils.test.ts, which covers escapePath for bash, pwsh and powershell. Without the fix, 18 of its 26 tests fail.
  • npm run build and npm run lint pass.
  • The other runtime tests pass, except brewInstallMullvad, which also fails on unmodified main on my machine (the local Homebrew prints no casks).
  • I have not yet tested this interactively in a Windows terminal.

🤖 Generated with Claude Code

PowerShell path suggestions were only quoted when they contained a space,
and embedded single quotes were escaped as \' (bash style). Inserting a
folder named `a$b`, `a&b` or `it's` therefore produced a command that
PowerShell parses differently (variable expansion, call operator,
unterminated string).

For pwsh and powershell, wrap the path in single quotes (literal strings)
when it contains whitespace or a character that is special in argument
mode (' " ` $ & | ; , ( ) { } < >, or a leading @ or #), and write
embedded single quotes as two single quotes. Other shells are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@aaaxingiiiiiii
aaaxingiiiiiii deleted the fix/pwsh-path-quoting branch October 15, 2026 06:37
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