Repository navigation
Closed
Labels
Area-FileSystem-Providerspecific to the FileSystem providerResolution-No ActivityIssue has had no activity for 6 months or moreWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Description
Was investigating escaping a filename for PowerShell in PowerShell/PowerShellEditorServices#765 (comment).
I created a directory with the following files:
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/11/2018 10:57 AM 9 [script.ps1
-a---- 10/11/2018 10:57 AM 1 `[script.ps1
-a---- 10/11/2018 10:57 AM 1 ``[script.ps1
-a---- 10/11/2018 10:57 AM 1 ```[script.ps1
-a---- 10/11/2018 10:57 AM 1 ````[script.ps1
-a---- 10/11/2018 10:57 AM 8 script.ps1
(New-Item doesn't seem to have a LiteralPath parameter by the way)
I then run the following:
foreach ($i in 0..12) { $ticks = '`' * $i; Get-Item "./$ticks[script.ps1" }Actual Results
The output of this in the given directory gives me:
Get-Item : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard character pattern is not valid: [script.ps1
At line:1 char:44
+ ... h ($i in 0..12) { $ticks = '`' * $i; Get-Item "./$ticks[script.ps1" }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Item], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemCommand
Directory: C:\Users\roholt\Documents\Dev\sandbox\badnames
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/11/2018 10:57 AM 9 [script.ps1
-a---- 10/11/2018 10:57 AM 9 [script.ps1
-a---- 10/11/2018 10:57 AM 1 `[script.ps1
Get-Item : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard character pattern is not valid: ``[script.ps1
At line:1 char:44
+ ... h ($i in 0..12) { $ticks = '`' * $i; Get-Item "./$ticks[script.ps1" }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Item], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemCommand
-a---- 10/11/2018 10:57 AM 1 ``[script.ps1
-a---- 10/11/2018 10:57 AM 1 `[script.ps1
-a---- 10/11/2018 10:57 AM 1 ```[script.ps1
Get-Item : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard character pattern is not valid: ````[script.ps1
At line:1 char:44
+ ... h ($i in 0..12) { $ticks = '`' * $i; Get-Item "./$ticks[script.ps1" }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Item], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemCommand
-a---- 10/11/2018 10:57 AM 1 ````[script.ps1
-a---- 10/11/2018 10:57 AM 1 ``[script.ps1
Get-Item : Cannot find path 'C:\Users\roholt\Documents\Dev\sandbox\badnames\`````[script.ps1' because it does not exist.
At line:1 char:44
+ ... h ($i in 0..12) { $ticks = '`' * $i; Get-Item "./$ticks[script.ps1" }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Users\roholt...````[script.ps1:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
Get-Item : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard character pattern is not valid: ``````[script.ps1
At line:1 char:44
+ ... h ($i in 0..12) { $ticks = '`' * $i; Get-Item "./$ticks[script.ps1" }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Item], ParameterBindingException
+ FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.Commands.GetItemCommand
More concretely:
> Get-Item './[script.ps1' # 0
# Error (The specified wildcard character pattern is not valid: [script.ps1)
> Get-Item './`[script.ps1' # 1
# Finds '[script.ps1'
> Get-Item './``[script.ps1' # 2
# Finds '[script.ps1' <--- ???
> Get-Item './```[script.ps1' # 3
# Finds '`[script.ps1'
> Get-Item './````[script.ps1' # 4
# Error (The specified wildcard character pattern is not valid: ``[script.ps1)
> Get-Item './`````[script.ps1' # 5
# Finds '``[script.ps1'
> Get-Item './``````[script.ps1' # 6
# Finds '`[script.ps1' <--- ???
> Get-Item './```````[script.ps1' # 7
# Finds '```[script.ps1'
> Get-Item './````````[script.ps1' # 8
# Error (The specified wildcard character pattern is not valid: ````[script.ps1)
> Get-Item './`````````[script.ps1' # 9
# Finds '````[script.ps1'
> Get-Item './``````````[script.ps1' # 10
# Finds '``[script.ps1' <--- ???
> Get-Item './```````````[script.ps1' # 11
# Error (Cannot find path 'C:\Users\roholt\Documents\Dev\sandbox\badnames\`````[script.ps1' because it does not exist.)
> Get-Item './````````````[script.ps1' # 12
# Error (The specified wildcard character pattern is not valid: ``````[script.ps1)
Cases 0, 1, 3, 4, 5, 7, 8, 9, 11 and 12 make sense. Cases 2, 6 and 10 seem pretty strange to me.
Expected Behaviour
Cases 2, 6 and 10 should report an invalid wildcard pattern, like cases 0, 4, 8 and 12.
Tagging James Truher (@JamesWTruher) because we discussed this offline earlier.
Reacted by 百地 希留耶, soredake, Daniel Tang, jantari and vanimathimdr-pixel
Reacted by Mr Beedell, Roke Julian Lockhart
Metadata
Metadata
Assignees
Labels
Area-FileSystem-Providerspecific to the FileSystem providerResolution-No ActivityIssue has had no activity for 6 months or moreWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Activity
rjmholt commentedon Oct 11, 2018
Trying to resolve the PSES issue linked above, I also tried the following:
[script.ps1,`[script.ps1,``[script.ps1, etc.0,1,2, etc. respectively (so the content of the file represents the number of backticks in the name).Here are my results:
I also tried invoking with a string literal:
rjmholt commentedon Oct 11, 2018
After discussing this further with James Truher (@JamesWTruher), we think one way to get around this is to use the fully provider-qualified name:
Microsoft.PowerShell.Core\FileSystem::C:\path\to\`[script.ps1iSazonov commentedon Oct 12, 2018
Rob Holt (@rjmholt) Please look #7399 - perhaps it could resolve the issue (fix for ContainsValidWildcardPattern).
kwkam commentedon Oct 12, 2018
I believe this is more related to the WildcardPatten escape & unescape inconsistency mentioned in #7407
mklement0 commentedon Jan 9, 2019
Re invocation with
./&: methinks the command-name argument should never be interpreted as a wildcard expression (though fixing that would technically be a breaking change) - see #4726To add to the cases of unexpected behaviors with
-Path: an argument that also contains unescaped wildcard characters introduces the unexpected need for an additional layer of escaping:Also, interestingly, performing the filtering via
-Includedoes not exhibit the bug:rjmholt commentedon Jan 9, 2019
I think this is the most important problem here; the input is unescaped a varying (and hard-to-predict) number of times, which undermines the whole concept of escaping to my mind.
zzJinux commentedon Jun 14, 2019
I think I found one more doubtful behavior. Please check if it's right
Reproduce
working directory:
Then run the following:
gi '``[``]'Expected
'``[``]'should be interpreted asBACKTICK META-LBRACKET BACKTICK META-RBRACKET, then match``Actual
mklement0 commentedon Sep 6, 2021
Rain Sallow (/u/ta11ow) (@vexx32) states that the WG decided that fixing this issue should also encompass a related fix for the native globbing feature - see #15959 (comment)
soredake commentedon Dec 5, 2023
Steven Bucher (@StevenBucher98) Ryan Yates (@kilasuit) can you reopen this, please?
danielzgtg commentedon May 2, 2024
This bug affects
Split-Pathmore severely:While
Get-Itemcan mention[script.ps1,Split-Pathcan't even mention it. The real-world use case I have isSplit-Path -Leaf -Resolve -Path '/path/to/dir/Title - of video [abc123].webm', and it's impossible to mention it without-LiteralPath, which has its own problems.plum7x commentedon Oct 20, 2024
There are some problem in Start-Process.
Backtick escaping does not work in
-RedirectStandardInputparam.Backtick escaping works in
-RedirectStandardErrorand-RedirectStandardOutput, but you will get the wrong file name.soredake commentedon Oct 21, 2025
Not stale.
microsoft-github-policy-service commentedon Jun 1, 2026
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.
0009-0009-1013-986X commentedon Sep 17, 2026
Has this actually been completed?
danielzgtg commentedon Sep 17, 2026
Probably not. It was closed for being stale