-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Steps to reproduce
Attempt to tab complete a share name on a UNC path via a partially resolved path that includes the provider notation.
get-content Microsoft.PowerShell.Core\FileSystem::\\rk-vs-fs1\ # press tab to cycle through the shares on the server.Expected behavior
I expected the same completions that I get with
get-content \\rk-vs-fs1\ # press tab to cycle through the shares on the server.Actual behavior
No completions occur
Analysis
Upon researching leads on #9881, it was noticed that this issue would occur in this code:
PowerShell/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs
Lines 4119 to 4142 in 981c990
| // First, try to match \\server\share | |
| var shareMatch = Regex.Match(wordToComplete, "^\\\\\\\\([^\\\\]+)\\\\([^\\\\]*)$"); | |
| if (shareMatch.Success) | |
| { | |
| // Only match share names, no filenames. | |
| var server = shareMatch.Groups[1].Value; | |
| var sharePattern = WildcardPattern.Get(shareMatch.Groups[2].Value + "*", WildcardOptions.IgnoreCase); | |
| var ignoreHidden = context.GetOption("IgnoreHiddenShares", @default: false); | |
| var shares = GetFileShares(server, ignoreHidden); | |
| foreach (var share in shares) | |
| { | |
| if (sharePattern.IsMatch(share)) | |
| { | |
| string shareFullPath = "\\\\" + server + "\\" + share; | |
| if (quote != string.Empty) | |
| { | |
| shareFullPath = quote + shareFullPath + quote; | |
| } | |
| results.Add(new CompletionResult(shareFullPath, shareFullPath, CompletionResultType.ProviderContainer, shareFullPath)); | |
| } | |
| } | |
| } | |
| else |
This particular code does not attempt to resolve the path name first to eliminate the potential 'filesystem' provider notation, before checking for a UNC '\server\share' pattern.
The 'filesystem' provider notation does not affect any other part of the tab completion logic, only the share name completion.
Do note, this code shown above appears to be responsible for #7569, as it fails to escape $ or spaces in the share names (or any other characters that might be legal in the share name but have a special meaning to PowerShell if not escaped or correctly quoted).