Support forward slashes in network share (UNC path) completion (#17111) (#17117)

This commit is contained in:
Stéphane BARIZIEN
2022-04-12 21:00:16 +05:00
committed by GitHub
parent 7cc9c87473
commit 4acf6b39d4
2 changed files with 15 additions and 4 deletions
@@ -4301,7 +4301,8 @@ namespace System.Management.Automation
var results = new List<CompletionResult>();
// First, try to match \\server\share
var shareMatch = Regex.Match(wordToComplete, "^\\\\\\\\([^\\\\]+)\\\\([^\\\\]*)$");
// support both / and \ when entering UNC paths for typing convenience (#17111)
var shareMatch = Regex.Match(wordToComplete, @"^(?:\\\\|//)([^\\/]+)(?:\\|/)([^\\/]*)$");
if (shareMatch.Success)
{
// Only match share names, no filenames.
@@ -140,7 +140,7 @@ switch ($x)
$res = TabExpansion2 -cursorColumn $CursorIndex -inputScript $TestString.Remove($CursorIndex, 1)
$res.CompletionMatches[0].CompletionText | Should -BeExactly $Expected
}
It 'Should Complete and replace existing member with space in front of cursor and cursor in front of word' {
$TestString = '[System.Management.Automation.ActionPreference]:: ^Break'
$CursorIndex = $TestString.IndexOf('^')
@@ -985,6 +985,16 @@ switch ($x)
$res.CompletionMatches[0].CompletionText | Should -BeExactly $afterTab
}
It "Tab completion UNC path with forward slashes" -Skip:(!$IsWindows) {
$beforeTab = "//localhost/admin"
# it is expected that tab completion turns forward slashes into backslashes
$afterTab = "\\localhost\ADMIN$"
$res = TabExpansion2 -inputScript $beforeTab -cursorColumn $beforeTab.Length
$res.CompletionMatches.Count | Should -BeGreaterThan 0
$res.CompletionMatches[0].CompletionText | Should -BeExactly $afterTab
}
It "Tab completion for registry" -Skip:(!$IsWindows) {
$beforeTab = 'registry::HKEY_l'
$afterTab = 'registry::HKEY_LOCAL_MACHINE'
@@ -1349,12 +1359,12 @@ dir -Recurse `
$res.CompletionMatches | Should -HaveCount 2
[string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "1.0,1.1"
}
It 'Should complete Select-Object properties without duplicates' {
$res = TabExpansion2 -inputScript '$PSVersionTable | Select-Object -Property Count,'
$res.CompletionMatches.CompletionText | Should -Not -Contain "Count"
}
It '<Intent>' -TestCases @(
@{
Intent = 'Complete loop labels with no input'