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:
ayousuf23
2022-02-09 12:59:29 -08:00
committed by GitHub
co-authored by Dongbo Wang
parent cf75ac58f7
commit a9a235d469
2 changed files with 9 additions and 1 deletions
@@ -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" {