terminal: preserve special characters in file names dropped into terminal#309187
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
terminal: preserve special characters in file names dropped into terminal#309187yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…inal Characters such as ~, !, #, $, ^, &, *, |, ;, <, > and backtick were silently stripped from file paths when dragging files from the Explorer into the terminal. This produced invalid paths pointing to non-existent files. The stripping was unnecessary: escapeNonWindowsPath always wraps paths in shell-appropriate quotes (e.g. single quotes for bash/sh/zsh), inside which all of those characters are treated as literals and cannot cause shell injection. Remove the bannedChars replacement and update the related test to assert the correct (preserving) behavior. Fixes microsoft#276999
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.
Characters such as
~,`,!,#,$,^,&,*,|,;,<,>were silently stripped from file paths when dragging files from the Explorer into the terminal. This produced invalid paths pointing to non-existent files.Root cause
escapeNonWindowsPathinsrc/vs/platform/terminal/common/terminalEnvironment.tsapplied abannedCharsregex replacement that removed those characters before quoting:Why the removal is both wrong and unnecessary
The function always wraps the resulting path in shell-appropriate quotes (single quotes for bash/sh/zsh,
$'...'ANSI C quoting when both quote types are present). Inside single quotes all of the listed characters are treated as literals — they cannot cause shell injection. Removing them was incorrect behavior that corrupted valid file names.Fix
Remove the
bannedCharsstripping. The quoting already provides full safety. Update the related test to assert the correct preserving behavior and add coverage for the affected characters.Test
The existing
'should remove dangerous characters'test has been renamed'should preserve special characters that are safe inside single quotes'with corrected expectations.Fixes #276999