Title: New-Item -Target parameter mishandles paths that look like wildcard patterns when creating symbolic links / reparse points · Issue #14534 · PowerShell/PowerShell · GitHub
Open Graph Title: New-Item -Target parameter mishandles paths that look like wildcard patterns when creating symbolic links / reparse points · Issue #14534 · PowerShell/PowerShell
X Title: New-Item -Target parameter mishandles paths that look like wildcard patterns when creating symbolic links / reparse points · Issue #14534 · PowerShell/PowerShell
Description: 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 PowerShel...
Open Graph Description: 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 tog...
X Description: 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...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/14534
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"New-Item -Target parameter mishandles paths that look like wildcard patterns when creating symbolic links / reparse points","articleBody":"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.\r\n\r\nBy contrast, in _Windows PowerShell_ you must _escape_ paths that _look like_ wildcard patterns, i.e. paths that contain `[` and `]`.\r\nUsing 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.\r\n\r\n## Steps to reproduce\r\n\r\n```powershell\r\nPush-Location ($tempDir = New-Item -Type Directory -Force \"temp:/$PID\")\r\n\r\ntry\r\n{\r\n\r\n # Use a file name with '[' and ']' - without that, the test would succeed.\r\n $target = Join-Path $pwd.ProviderPath '[1] file.txt'\r\n\r\n # Create the file.\r\n $null = New-Item -Path $target -Value hi -Force\r\n\r\n # Try to create a symlink named 'lnk' in subdir. 'sub' (to be created on demand\r\n # with -Force) pointing to the newly created file.\r\n # Note:\r\n # If ([WildcardPattern]::Escape($target)) is used to escape the path,\r\n # the command *seemingly* succeeds, but the *escaped* path is mistakenly\r\n # used *verbatim* as the target, quietly resulting in a *broken link*.\r\n { New-Item -ErrorAction Stop -Path sub/lnk -Type SymbolicLink -Force -Target $target } |\r\n Should -Not -Throw\r\n\r\n} finally {\r\n\r\n Pop-Location\r\n Remove-Item -ErrorAction Ignore -LiteralPath $tempDir -Recurse -Force\r\n\r\n}\r\n```\r\n\r\n## Expected behavior\r\n\r\nThe test should succeed.\r\n\r\n## Actual behavior\r\n\r\nThe test fails, because (by design _unescaped_) `$target` isn't recognized as an existing item, even though the error message correctly lists the path:\r\n\r\n```none\r\n...\r\nCannot find path '.../[1] file.txt' because it does not exist.\r\n...\r\n```\r\n\r\n## Environment data\r\n\r\n```none\r\nPowerShell Core 7.2.0-preview.2\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2021-01-03T17:28:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/14534/PowerShell/issues/14534"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4df32a96-7c0b-638d-2b8c-a62a82534ab4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93F2:B0627:72204E:A1CFD3:6A587986 |
| html-safe-nonce | ee772ece3b36cc70e556de7f0a7e58c4f0d5fb6c3608a9f57a5115178faad825 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0YyOkIwNjI3OjcyMjA0RTpBMUNGRDM6NkE1ODc5ODYiLCJ2aXNpdG9yX2lkIjoiNjEyMzc1MzY3Nzk1MjQxNjEzNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 843cbd78fa0fa1df275f589a56d9ea2eb3006a438a5f84a5e2d2a32235c196a2 |
| hovercard-subject-tag | issue:777681746 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/14534/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b7b360918a0a54455648cbb27ced04ab776a936bf1b11619b31ab43ea83fd664/PowerShell/PowerShell/issues/14534 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b7b360918a0a54455648cbb27ced04ab776a936bf1b11619b31ab43ea83fd664/PowerShell/PowerShell/issues/14534 |
| og:image:alt | 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 tog... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f2a0c7865178af3d91dd9f13b0cdfc3c73a2529c873d2780bb4c01271a57ec6 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8aae7b8d6caacacf5c66eaeb2702d8dc88d85b4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width