Skip to content

Get-ChildItem: wildcard matching behavior differs between -Path and -Include parameters when using escape characters #3724

Closed

Description

Note:

  • Get-Item appears not to be affected, only Get-ChildItem
  • Problem exists on all supported platforms.

Wildcard patterns support ` as the escape character to represent literal ` instances in the filename and to escape the following metacharacters: * ? [ ]

Steps to reproduce

# Create a file that contains a literal backtick and a literal substring that would be a valid
# sub-pattern if interpreted as a wildcard expression.
New-Item -Type File 'a`[b]'

# Match the newly created file using a wildcard expression with suitable escaping.
# The following 2 command should be equivalent, but currently aren't.
Get-ChildItem * -Include 'a```[b`]'
Get-ChildItem -Path 'a```[b`]'

Expected behavior

Both Get-ChildItem commands should match the newly created file and output information about it.

Actual behavior

The 2nd command unexpectedly fails:

Get-ChildItem : Cannot find path '/Users/jdoe/a```[b`]' because it does not exist.
...

Again, note that Get-Item does not exhibit this problem.

Environment data

PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on macOS 10.12.4
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Ubuntu 16.04.1 LTS
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Microsoft Windows 10 Pro (64-bit; v10.0.14393)

Activity

  1. iSazonov commented on May 8, 2017

    @iSazonov
    Collaborator

    Related #3414

    Is it only macOS issue?

  2. mklement0 commented on May 8, 2017

    @mklement0
    ContributorAuthor

    Ilya (@iSazonov): No, it affects all supported platforms - I've updated the original post to make that clear.

  3. added this to the milestone on May 22, 2017
  4. mklement0 commented on Sep 5, 2019

    @mklement0
    ContributorAuthor

    I don't know what fixed it, but the problem no longer occurs as of PowerShell Core 7.0.0-preview.3

  5. iSazonov commented on Sep 5, 2019

    @iSazonov
    Collaborator

    Michael Klement (@mklement0) Should we add a test to exclude regression or we already have it?

  6. mklement0 commented on Sep 5, 2019

    @mklement0
    ContributorAuthor

    Ilya (@iSazonov) Providing such tests sounds like a good idea, given that we don't know why the problem went away and given that there'll be a v2 filesystem provider.

    I haven't explicitly checked if we already have such tests, but I'd be surprised if we did, given that this problem was seemingly never tackled as such.

    On a quick meta note: I know you've pinged me on a few other issues, but the bigger ones I haven't had the time and energy to respond to, but I generally appreciate your systematic efforts to reach out to others (who may care / have something to contribute) in the discussions.

  7. iSazonov commented on Sep 5, 2019

    @iSazonov
    Collaborator

    Michael Klement (@mklement0) I do not expect an immediate reaction to pings. I just hope you get some interesting links for thought. Your reviews is always great!

    I will add a test for the issue. Thanks!

  8. iSazonov commented on Sep 5, 2019

    @iSazonov
    Collaborator

    Perhaps kwkam could reference a PR where the issue was fixed.

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-BugIssue has been identified as a bug in the productWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions