You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New-Item -Target parameter mishandles paths that look like wildcard patterns when creating symbolic links / reparse points #14534
Note: I'm writing this bug report from the perspective of the green-lit proposal to interpret -Target arguments as literal (verbatim) paths - see #13136. Perhaps these two issues can be tackled together.
By contrast, in Windows PowerShell you must escape paths that look like wildcard patterns, i.e. paths that contain [ and ].
Using this escaping as of PowerShell Core in 7.2.0-preview.2 doesn't work either, however, because the escaped path, while recognized as an existing item, is them mistakenly used verbatim as the link's target, resulting in a broken link.
Steps to reproduce
Push-Location ($tempDir=New-Item-Type Directory -Force "temp:/$PID")
try
{
# Use a file name with '[' and ']' - without that, the test would succeed.$target=Join-Path$pwd.ProviderPath'[1] file.txt'# Create the file.$null=New-Item-Path $target-Value hi -Force
# Try to create a symlink named 'lnk' in subdir. 'sub' (to be created on demand# with -Force) pointing to the newly created file.# Note:# If ([WildcardPattern]::Escape($target)) is used to escape the path,# the command *seemingly* succeeds, but the *escaped* path is mistakenly# used *verbatim* as the target, quietly resulting in a *broken link*.
{ New-Item-ErrorAction Stop -Path sub/lnk -Type SymbolicLink -Force -Target $target } |
Should -Not-Throw
} finally {
Pop-LocationRemove-Item-ErrorAction Ignore -LiteralPath $tempDir-Recurse -Force
}
Expected behavior
The test should succeed.
Actual behavior
The test fails, because (by design unescaped) $target isn't recognized as an existing item, even though the error message correctly lists the path:
...
Cannot find path '.../[1] file.txt' because it does not exist.
...
Environment data
PowerShell Core 7.2.0-preview.2
Reacted by Rodrigo Machuca, mtone and Hashbrown777
Thanks, abaumgaertner (@abaumgaertner), you probably meant New-Item -Type SymbolicLink foo -Target ([WildcardPattern]::Escape('abcd [bla]')) (wrong type, missing ((...)), but, as stated in the initial post, this doesn't actually work:
The command seemingly succeeds,
but the resulting symlink is broken, because the escaped name is used verbatim as the target path.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Reacted by Hashbrown777
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
I feel like biannually creating duplicate issues is not a productive way to see if issues still exist.
microsoft-github-policy-service commented on Nov 25, 2023
Activity
abaumgaertner commentedon Apr 5, 2021
workaround: New-Item -Type Directory -Target [WildcardPattern]::Escape('abcd [bla]')
similar issues: #6232
mklement0 commentedon Apr 5, 2021
Thanks, abaumgaertner (@abaumgaertner), you probably meant
New-Item -Type SymbolicLink foo -Target ([WildcardPattern]::Escape('abcd [bla]'))(wrong type, missing ((...)), but, as stated in the initial post, this doesn't actually work:mklement0 commentedon Apr 6, 2021
@OctaneTwisted found that escaping twice(!) is an effective workaround: #6232 (comment)
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Hashbrown777 commentedon Nov 18, 2023
I feel like biannually creating duplicate issues is not a productive way to see if issues still exist.
microsoft-github-policy-service commentedon Nov 25, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.