Repository navigation
fix: quote PowerShell paths containing special characters - #488
Closed
aaaxingiiiiiii wants to merge 1 commit into
Closed
aaaxingiiiiiii wants to merge 1 commit into
aaaxingiiiiiii wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:a$ba$b/$bas a variablea&ba&b/&is the call operatorit'sit's/it's dir'it\'s dir/'\is not an escape character, so the string ends earlyThis 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
src/tests/runtime/utils.test.ts, which coversescapePathfor bash, pwsh and powershell. Without the fix, 18 of its 26 tests fail.npm run buildandnpm run lintpass.brewInstallMullvad, which also fails on unmodifiedmainon my machine (the local Homebrew prints no casks).🤖 Generated with Claude Code