-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix tab completion for filename contains literal wildcard character #7407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
931f073
b8ce02f
27cd737
7ab5699
c710d39
40fd00a
98086fc
8b8c2ed
811b574
a09ac29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4398,6 +4398,12 @@ internal static IEnumerable<CompletionResult> CompleteFilename(CompletionContext | |
| if (CompletionRequiresQuotes(completionText, !useLiteralPath)) | ||
| { | ||
| var quoteInUse = quote == string.Empty ? "'" : quote; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should all changes be behind the experimental feature?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a condition of the committee
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Except filename completion will now also escape |
||
| if (!useLiteralPath) | ||
| { | ||
| completionText = WildcardPattern.Escape(completionText); | ||
| } | ||
|
|
||
| if (quoteInUse == "'") | ||
| { | ||
| completionText = completionText.Replace("'", "''"); | ||
|
|
@@ -4410,20 +4416,6 @@ internal static IEnumerable<CompletionResult> CompleteFilename(CompletionContext | |
| completionText = completionText.Replace("$", "`$"); | ||
| } | ||
|
|
||
| if (!useLiteralPath) | ||
| { | ||
| if (quoteInUse == "'") | ||
| { | ||
| completionText = completionText.Replace("[", "`["); | ||
| completionText = completionText.Replace("]", "`]"); | ||
| } | ||
| else | ||
| { | ||
| completionText = completionText.Replace("[", "``["); | ||
| completionText = completionText.Replace("]", "``]"); | ||
| } | ||
| } | ||
|
|
||
| completionText = quoteInUse + completionText + quoteInUse; | ||
| } | ||
| else if (quote != string.Empty) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3360,13 +3360,11 @@ private List<string> GenerateNewPSPathsWithGlobLeaf( | |
| StringContainsGlobCharacters(leafElement) || | ||
| isLastLeaf) | ||
| { | ||
| string regexEscapedLeafElement = ConvertMshEscapeToRegexEscape(leafElement); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain this change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As explained in the PR Summary,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can I mark this resolved? |
||
|
|
||
| // Construct the glob filter | ||
|
|
||
| WildcardPattern stringMatcher = | ||
| WildcardPattern.Get( | ||
| regexEscapedLeafElement, | ||
| leafElement, | ||
| WildcardOptions.IgnoreCase); | ||
|
|
||
| // Construct the include filter | ||
|
|
@@ -3966,13 +3964,11 @@ internal List<string> GenerateNewPathsWithGlobLeaf( | |
| (StringContainsGlobCharacters(leafElement) || | ||
| isLastLeaf)) | ||
| { | ||
| string regexEscapedLeafElement = ConvertMshEscapeToRegexEscape(leafElement); | ||
|
|
||
| // Construct the glob filter | ||
|
|
||
| WildcardPattern stringMatcher = | ||
| WildcardPattern.Get( | ||
| regexEscapedLeafElement, | ||
| leafElement, | ||
| WildcardOptions.IgnoreCase); | ||
|
|
||
| // Construct the include filter | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,68 @@ | ||||||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| # Licensed under the MIT License. | ||||||
|
|
||||||
| Describe "WildcardPattern Escape - Experimental-Feature-Disabled" -Tags "CI" { | ||||||
kwkam marked this conversation as resolved.
Show resolved
Hide resolved
kwkam marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| BeforeAll { | ||||||
| $testName = 'PSWildcardEscapeEscape' | ||||||
| $skipTest = $EnabledExperimentalFeatures.Contains($testName) | ||||||
|
|
||||||
| if ($skipTest) { | ||||||
| Write-Verbose "Test Suite Skipped. The test suite requires the experimental feature '$testName' to be disabled." -Verbose | ||||||
| $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() | ||||||
| $PSDefaultParameterValues["it:skip"] = $true | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| AfterAll { | ||||||
| if ($skipTest) { | ||||||
| $global:PSDefaultParameterValues = $originalDefaultParameterValues | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| It "Unescaping '<escapedStr>' which escaped from '<inputStr>' should get the original" -TestCases @( | ||||||
| @{inputStr = '*This'; escapedStr = '`*This'} | ||||||
| @{inputStr = 'Is?'; escapedStr = 'Is`?'} | ||||||
| @{inputStr = 'Real[ly]'; escapedStr = 'Real`[ly`]'} | ||||||
| @{inputStr = 'Ba`sic'; escapedStr = 'Ba`sic'} | ||||||
| @{inputStr = 'Test `[more`]?'; escapedStr = 'Test ``[more``]`?'} | ||||||
| ) { | ||||||
| param($inputStr, $escapedStr) | ||||||
|
|
||||||
| [WildcardPattern]::Escape($inputStr) | Should -BeExactly $escapedStr | ||||||
| [WildcardPattern]::Unescape($escapedStr) | Should -BeExactly $inputStr | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| Describe "WildcardPattern Escape - Experimental-Feature-Enabled" -Tags "CI" { | ||||||
|
|
||||||
| BeforeAll { | ||||||
| $testName = 'PSWildcardEscapeEscape' | ||||||
| $skipTest = -not $EnabledExperimentalFeatures.Contains($testName) | ||||||
|
|
||||||
| if ($skipTest) { | ||||||
| Write-Verbose "Test Suite Skipped. The test suite requires the experimental feature '$testName' to be enabled." -Verbose | ||||||
| $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() | ||||||
| $PSDefaultParameterValues["it:skip"] = $true | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| AfterAll { | ||||||
| if ($skipTest) { | ||||||
| $global:PSDefaultParameterValues = $originalDefaultParameterValues | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| It "Unescaping '<escapedStr>' which escaped from '<inputStr>' should get the original" -TestCases @( | ||||||
| @{inputStr = '*This'; escapedStr = '`*This'} | ||||||
| @{inputStr = 'Is?'; escapedStr = 'Is`?'} | ||||||
| @{inputStr = 'Real[ly]'; escapedStr = 'Real`[ly`]'} | ||||||
| @{inputStr = 'Ba`sic'; escapedStr = 'Ba``sic'} | ||||||
| @{inputStr = 'Test `[more`]?'; escapedStr = 'Test ```[more```]`?'} | ||||||
| ) { | ||||||
| param($inputStr, $escapedStr) | ||||||
|
|
||||||
| [WildcardPattern]::Escape($inputStr) | Should -BeExactly $escapedStr | ||||||
| [WildcardPattern]::Unescape($escapedStr) | Should -BeExactly $inputStr | ||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.