Skip to content

The FileSystem provider does not reliably report invalid wildcard patterns #6733

@mklement0

Description

@mklement0

See also: #12168

Note: This is an obscure edge case.

For the most part, malformed wildcard patterns are quietly ignored and fall back to literal treatment (e.g., Get-Item a].txt matches a file literally named a].txt) - that inconsistency could be considered problematic in itself, however.

Update: A pattern such as a].txt is actually valid, because the ] is not special unless preceded by [. However, patterns such as a[].txt and a[.txt and a[foo.txt are invalid, and the problem is that they are not consistently reported as such. The rest of this post has been revised accordingly.

When an invalid wildcard pattern - e.g., one that ends in [] before the filename extension - is passed to Get-Item or Get-ChildItem, the error that should occur occurs only if at least two files exists that have the same matching prefix (the exact logic is not clear to me).

(@BrucePay states that the source of the error is the FileSystem provider itself, not the cmdlets mentioned.)

Steps to reproduce

# Assume that no `tmp*.txt` files exist.
Get-Item tmp[].txt
'---'
$null = New-Item -Force tmp.txt; Get-Item tmp[].txt

Expected behavior

Get-Item : Cannot retrieve the dynamic parameters for the cmdlet. 
The specified wildcard character pattern is not valid: tmp[].txt
---
Get-Item : Cannot retrieve the dynamic parameters for the cmdlet. 
The specified wildcard character pattern is not valid: tmp[].txt

That is, two instances of the same The specified wildcard character pattern is not valid error should occur, irrespective of whether any tmp*.txt files exist or not.

Actual behavior

---
Get-Item : Cannot retrieve the dynamic parameters for the cmdlet. 
The specified wildcard character pattern is not valid: tmp[].txt

That is, in the absence of any tmp*.txt files, the invalid wildcard expression was not reported as invalid.

Environment data

Originally reported for 6.0.2, updated for:

PowerShell Core v7.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerBreaking-Changebreaking change that may affect usersIssue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-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