Skip to content

fix: preserve special characters when dropping files into terminal#295355

Open
4RH1T3CT0R7 wants to merge 2 commits intomicrosoft:mainfrom
4RH1T3CT0R7:fix/terminal-path-special-chars
Open

fix: preserve special characters when dropping files into terminal#295355
4RH1T3CT0R7 wants to merge 2 commits intomicrosoft:mainfrom
4RH1T3CT0R7:fix/terminal-path-special-chars

Conversation

@4RH1T3CT0R7
Copy link
Copy Markdown

@4RH1T3CT0R7 4RH1T3CT0R7 commented Feb 14, 2026

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.sh becomes '/home/user/filev1.sh' (tilde lost).

Root cause

escapeNonWindowsPath() contains a bannedChars regex 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

  • Remove the bannedChars regex - single-quote wrapping already neutralizes all special characters
  • Fix Fish bothQuotes handler - escape $ inside double-quoted paths (for the rare case where a path contains both ' and ")
  • Fix PowerShell bothQuotes handler - escape ` and $ inside double-quoted paths

Test plan

  • Updated unit tests: replaced "should remove dangerous characters" with tests verifying all 12 special characters are preserved
  • Added tests for injection patterns ($(echo evil), `whoami`) confirming they are safely quoted
  • Added tests for Fish and PowerShell bothQuotes $-escaping
  • Updated 8 integration test expectations across all shell/platform combinations

Copilot AI review requested due to automatic review settings February 14, 2026 18:29
@4RH1T3CT0R7
Copy link
Copy Markdown
Author

@4RH1T3CT0R7 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bannedChars regex 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

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.

Dragging-n-dropping a file with tilde in the name into terminal

4 participants