Skip to content

PSNativePSPathResolution breaks passing strings starting with ":" to native tools #13638

Closed

Description

Steps to reproduce

PS> cmd /c echo ":(top,exclude).*"

Expected behavior

:(top,exclude).*

Actual behavior

C:\Users\duhowett\src\openconsole-inbox\:(top,exclude).*

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0-preview.7
PSEdition                      Core
GitCommitId                    7.1.0-preview.7
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

It appears as though the check here

if (path.Contains(':'))
{
LocationGlobber globber = new LocationGlobber(context.SessionState);
try
{
ProviderInfo providerInfo;
// replace the argument with resolved path if it's a filesystem path
string pspath = globber.GetProviderPath(path, out providerInfo);
if (string.Equals(providerInfo.Name, FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
{
path = pspath;
}
}
catch
{
// if it's not a provider path, do nothing
}
}

is not strict enough.

I encountered this by trying to use a git globbing expression, which can begin with : to introduce a set of flags.

PS> & git log ":(top,exclude).git/" ":(top,exclude)**/*.rec"
fatal: invalid object name 'C'.

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Sep 15, 2020
  2. DHowett commented on Sep 15, 2020

    @DHowett
    Author

    (This broke an existing script that we were using to generate git logs.)

  3. DHowett commented on Sep 15, 2020

    @DHowett
    Author

    (We cannot figure out how to get :x to behave normally.)

  4. mklement0 commented on Sep 15, 2020

    @mklement0
  5. mklement0 commented on Sep 15, 2020

    @mklement0
    Contributor

    As for the root cause: please see #13640 - I suggest you close this issue in favor of the latter.
    [Edit: I missed that you've commendably already done all the hard analysis work, but the linked issue may still be a more succinct formulation, complete with tests.]

    Another workaround (apart from using --%) on Windows is to use '...' rather than "..." quoting, though the fact that this works is arguably a separate bug:

    # On Windows:
    PS> cmd /c echo  ':(top,exclude).git/' ':(top,exclude)**/*.rec'
    :(top,exclude).git/ :(top,exclude)**/*.rec
  6. added
    WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
    on Sep 16, 2020
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

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions