-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Open
Labels
Area-FileSystem-Providerspecific to the FileSystem providerspecific to the FileSystem providerWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.built-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 @JamesWTruher because we discussed this offline earlier.
KiruyaMomochi, soredake, danielzgtg, jantari and vanimathimdr-pixelRokeJulianLockhart
Metadata
Metadata
Assignees
Labels
Area-FileSystem-Providerspecific to the FileSystem providerspecific to the FileSystem providerWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.