Closed danielzgtg closed 2 weeks ago
but
-LiteralPath
doesn't support-Leaf
, etc.
That is an unfortunate bug, which - while having been acknowledged as such - still hasn't been fixed:
That said, there's still a separate bug here:
With a file literally named hi [123].txt
present in the current directory, both the following commands should output hi [123].txt
, but currently don't:
Split-Path -Leaf -Resolve -Path h*
Split-Path -Leaf -Resolve -Path ([WildcardPattern]::Escape('hi [123].txt'))
Note that Split-Path -Leaf -Resolve -Path h*
does find items whose names start with h
but do not also contain [
and ]
, say, a file named hi noon
.
It seems PowerShell is incorrectly expanding the wildcard twice:
bash:/tmp$ touch 'hi 123].txt'
bash:/tmp$ pwsh
PowerShell 7.4.1
PS /tmp> Split-Path -Leaf -Resolve -Path h*
hi 123].txt
PS /tmp> Split-Path -Leaf -Resolve -Path 'hi 123].txt'
hi 123].txt
PS /tmp> Split-Path -Leaf -Resolve -Path 'hi 123`].txt'
hi 123].txt
PS /tmp> Split-Path -Leaf -Resolve -Path 'hi 123``].txt'
hi 123].txt
PS /tmp> bash:/tmp$ touch 'hi [123.txt'
bash:/tmp$ pwsh
PowerShell 7.4.1
PS /tmp> Split-Path -Leaf -Resolve -Path h*
Split-Path: The specified wildcard character pattern is not valid: hi [123.txt
PS /tmp> Split-Path -Leaf -Resolve -Path 'hi [123.txt'
Split-Path: The specified wildcard character pattern is not valid: hi [123.txt
PS /tmp> Split-Path -Leaf -Resolve -Path 'hi `[123.txt'
Split-Path: The specified wildcard character pattern is not valid: hi [123.txt
PS /tmp> Split-Path -Leaf -Resolve -Path 'hi ``[123.txt'
See also:
7999
That looks like the root cause. Closing in favor of it.
📣 Hey @danielzgtg, how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback
Prerequisites
Steps to reproduce
Split-Path -Resolve -Path
can't see any[]
-filenamed files while other commands likeGet-Item
can. This only affects-Path
not-LiteralPath
but-LiteralPath
doesn't support-Leaf
, etc.Expected behavior
Actual behavior
Error details
Environment data
Visuals
No response