KEMBAR78
tab completion of a provider path notation UNC share name is not possible · Issue #10002 · PowerShell/PowerShell · GitHub
Skip to content

tab completion of a provider path notation UNC share name is not possible #10002

@msftrncs

Description

@msftrncs

related to #7569 and #9881

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:

// 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-Enhancementthe issue is more of a feature request than a bugWG-Interactive-IntelliSensetab completion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions