fix: separate PosixShellType.Sh case with POSIX-safe single-quote escaping - #334988
Open
Viraj Mishra (VirajMishra1) wants to merge 2 commits into
Open
fix: separate PosixShellType.Sh case with POSIX-safe single-quote escaping#334988Viraj Mishra (VirajMishra1) wants to merge 2 commits into
Viraj Mishra (VirajMishra1) wants to merge 2 commits into
Conversation
…aping POSIX sh does not support ANSI-C $'...' quoting. When a path contains a single quote, the existing code fell through to the Bash case and emitted $'...\\'...' which sh rejects. Fix: give PosixShellType.Sh its own case using close-quote/escaped-quote/ reopen-quote: path.replace(/'/g, "'\\''"). Also tighten collapseTildePath to check startsWith(home + separator) so /home/user2 is not collapsed when home is /home/user. Add regression tests for both cases.
Copilot started reviewing on behalf of
Viraj Mishra (VirajMishra1)
September 7, 2026 22:58
View session
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Anthony Kim (@anthonykim1)Matched files:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical test expectation failures and missing quote-combination coverage must be addressed.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Separates POSIX sh escaping and tightens home-path collapsing.
Changes:
- Adds POSIX-safe single-quote escaping.
- Prevents false tilde-path collapses.
- Adds path-boundary regression tests.
File summaries
| File | Review |
|---|---|
src/vs/platform/terminal/test/common/terminalEnvironment.test.ts |
Adds tilde-collapse tests, but shell-escaping expectations and bothQuotes coverage require updates. |
src/vs/platform/terminal/common/terminalEnvironment.ts |
Updates shell escaping and home-path matching; current changes conflict with existing Bash, Zsh, Git Bash, and sh assertions. |
Review details
Suppressed comments (1)
src/vs/platform/terminal/common/terminalEnvironment.ts:69
- The default branch now returns
'/foo/bar'\''baz', butterminalEnvironment.test.ts:97still asserts the previous'/foo/bar\'baz'output. This leaves the unit suite failing; update the default-shell expectation to the new POSIX form.
bothQuotes: (path) => `'${path.replace(/'/g, `'\\''`)}'`,
singleQuotes: (path) => `'${path.replace(/'/g, `'\\''`)}'`,
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+35
to
+36
| bothQuotes: (path) => `'${path.replace(/'/g, `'\\''`)}'`, | ||
| singleQuotes: (path) => `'${path.replace(/'/g, `'\\''`)}'`, |
| escapeConfig = { | ||
| bothQuotes: (path) => `$'${path.replace(/'/g, '\\\'')}'`, | ||
| singleQuotes: (path) => `'${path.replace(/'/g, '\\\'')}'`, | ||
| singleQuotes: (path) => `$'${path.replace(/'/g, '\\\'')}'`, |
- Bash/Zsh/GitBash now use ANSI-C $'...' quoting for single-quote paths - PosixShellType.Sh and unknown shells use POSIX close/escape/reopen - Split bash/sh/zsh test into two suites (different output formats) - Add Sh bothQuotes coverage for paths with both single and double quotes - Update default-shell test to expect POSIX form
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.
What does this implement/fix?
POSIX
shdoes not support ANSI-C$'...'quoting. The existing code groupedPosixShellType.ShwithBashin a fall-through case, so a path containing a single quote produced$'...\\'...'— valid in Bash but a syntax error in/bin/sh.Fix: Give
PosixShellType.Shits own case using the POSIX-portable close-quote/escaped-quote/reopen-quote idiom: replace each'with'\'').Also tightens
collapseTildePathto checkstartsWith(normalizedUserHome + '/')(or equality) instead ofincludes, so/home/user2is not incorrectly collapsed when home is/home/user.Regression tests added for both fixes.
AI usage disclosure
I used AI assistance for: