mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Prevent tab completion if the word to complete is a single dash (#16781)
* added code to prevent tab completion if the word to complete is a single dash * added a test for testing tab completion if the word to complete is a single dash * Minor update and add comment Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
This commit is contained in:
@@ -1329,7 +1329,8 @@ namespace System.Management.Automation
|
||||
context.Options.Remove("LiteralPaths");
|
||||
}
|
||||
|
||||
if (context.WordToComplete != string.Empty && context.WordToComplete.Contains('-'))
|
||||
// The word to complete contains a dash and it's not the first character. We try command names in this case.
|
||||
if (context.WordToComplete.IndexOf('-') > 0)
|
||||
{
|
||||
var commandResults = CompleteCommand(context);
|
||||
if (commandResults != null)
|
||||
|
||||
@@ -1435,6 +1435,13 @@ dir -Recurse `
|
||||
$res = TabExpansion2 -inputScript $inputStr -cursorColumn $inputStr.Length
|
||||
$res.CompletionMatches | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "A single dash should not complete to anything" {
|
||||
function test-{}
|
||||
$inputStr = 'git -'
|
||||
$res = TabExpansion2 -inputScript $inputStr -cursorColumn $inputStr.Length
|
||||
$res.CompletionMatches | Should -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Context "Tab completion error tests" {
|
||||
|
||||
Reference in New Issue
Block a user