fix: preserve special characters when dropping files into terminal#295355
Open
4RH1T3CT0R7 wants to merge 2 commits intomicrosoft:mainfrom
Open
fix: preserve special characters when dropping files into terminal#2953554RH1T3CT0R7 wants to merge 2 commits intomicrosoft:mainfrom
4RH1T3CT0R7 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Author
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where dragging files with special characters (like ~, `, !, #, $, ^, &, *, |, ;, <, >) from the Explorer into the Terminal would silently strip those characters from the path, corrupting file paths.
Changes:
- Removed the
bannedCharsregex that was stripping special characters from paths before quoting - Added
$escaping in Fish shell's double-quoted path handler - Added backtick and
$escaping in PowerShell's double-quoted path handler - Updated unit and integration tests to verify special characters are preserved
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/vs/platform/terminal/common/terminalEnvironment.ts | Removed bannedChars regex; added $ escaping for Fish and $/backtick escaping for PowerShell in double-quoted paths |
| src/vs/platform/terminal/test/common/terminalEnvironment.test.ts | Replaced "dangerous characters" test with comprehensive tests for special character preservation and injection pattern safety |
| src/vs/workbench/contrib/terminal/test/common/terminalEnvironment.test.ts | Updated integration tests to expect $(echo evil) to be preserved in all shell types |
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.
Fixes #276999
Problem
Dragging a file with special characters (
~,`,!,#,$,^,&,*,|,;,<,>) in its name from the Explorer into the Terminal silently strips those characters from the path. This corrupts file paths and can cause users to unknowingly reference the wrong file.Example:
/home/user/file~v1.shbecomes'/home/user/filev1.sh'(tilde lost).Root cause
escapeNonWindowsPath()contains abannedCharsregex that removes special characters from the path before quoting. Since the function already wraps paths in single quotes - where all characters are literal in POSIX shells (bash, zsh, sh, fish) and PowerShell - the stripping is unnecessary and actively harmful.Fix
bannedCharsregex - single-quote wrapping already neutralizes all special charactersbothQuoteshandler - escape$inside double-quoted paths (for the rare case where a path contains both'and")bothQuoteshandler - escape`and$inside double-quoted pathsTest plan
$(echo evil),`whoami`) confirming they are safely quotedbothQuotes$-escaping