diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index a81027ed98..acdbe2233b 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -4301,7 +4301,8 @@ namespace System.Management.Automation var results = new List(); // 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. diff --git a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 index 9522ee56c3..f984e3b72c 100644 --- a/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 @@ -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 '' -TestCases @( @{ Intent = 'Complete loop labels with no input'