Skip to content

path completion of unc paths with spaces fails to quote resulting path #7569

Closed

Description

@msftrncs

Steps to reproduce

Start a path to a command, in this case,

cd \\svr\

Press CTRL-SPACE (<-EDITED) to bring up completion suggestions, which list all the shares on '\\svr\'.

Select a share that contains a space (notice the highlight fails to clear off entries as you move through the list).

Expected behavior

quotes (') should be added around the UNC path which contains characters that need escaped or quoted.

Actual behavior

Immediately you will notice there is no quote characters being inserted into the completion, and this prevents completing the next step in the path.

Side note, Windows PowerShell 5.1 seems to have the same problem with UNC paths, but at least the highlight works correctly.

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.3
PSEdition                      Core
GitCommitId                    v6.0.3
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. iSazonov commented on Aug 20, 2018

    @iSazonov
    Collaborator

    Carl Morris (@msftrncs) Could you please test with latest build (6.0.4)? Is the problem without PSReadline module?

  2. msftrncs commented on Aug 20, 2018

    @msftrncs
    ContributorAuthor

    I tested with the Windows edition of 6.0.4 this morning, still the same result. Are you referring to having made any updates to PSReadLine module? No, I have no additions to PowerShell installed, nor upgraded the PSReadLine module.

  3. msftrncs commented on Aug 20, 2018

    @msftrncs
    ContributorAuthor

    including a screenshot

    image

  4. iSazonov commented on Aug 22, 2018

    @iSazonov
    Collaborator

    Carl Morris (@msftrncs) Please unload PSReadline module and test.

  5. msftrncs commented on Aug 22, 2018

    @msftrncs
    ContributorAuthor

    After much work, I finally got the latest beta of PSReadLine (2.0.0 beta 2 release) to import in to PowerShell Core, and the issue remains with the non-quoting of paths that require quoting, but the highlight no longer sticks to every entry touched.

    PowerShell Core specific items like paths, could use to be mentioned in the PSReadLine readme.

  6. iSazonov commented on Aug 23, 2018

    @iSazonov
    Collaborator

    I can repo with and w/o PSReadline for share names with spaces (not for folder names in shares).

  7. msftrncs commented on Aug 24, 2018

    @msftrncs
    ContributorAuthor

    Sorry for not noticing this earlier, it also is an issue for other invalid characters as well, in this case, on the hidden share names, C$, E$, F$ ect. Its also a problem if you already had quotes, say CD "\\SVR\" and then complete with a share name with the $, the $ is not escaped. Yes, once past the share portion, sub folders with an invalid character are no longer a problem, including proper escaping of ` and $

  8. msftrncs commented on Jun 25, 2019

    @msftrncs
    ContributorAuthor

    I think I found the source of this, while referencing #9881,

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

    At this point it is looking like no escaping ever occurs on the resulting shares made available for completion, past this point, it appears that file names are escaped before being returned.

  9. added 2 commits that reference this issue on Jul 24, 2019
    397988b
  10. added a commit that references this issue on Dec 2, 2019
    cd71de2
  11. ghost added
    In-PRIndicates that a PR is out for the issue
    on Apr 2, 2023
  12. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  13. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  14. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  15. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

  16. microsoft-github-policy-service commented on Feb 25, 2025

    @microsoft-github-policy-service
    Contributor

    📣 Hey Carl Morris (@msftrncs), how did we do? We would love to hear your feedback with the link below! 🗣️

    🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productWG-Interactive-IntelliSensetab completion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions