Title: Passing an escaped wildcard expression to -Path in file-creating cmdlets causes the escaped representation to be used as the literal filename · Issue #9475 · PowerShell/PowerShell · GitHub
Open Graph Title: Passing an escaped wildcard expression to -Path in file-creating cmdlets causes the escaped representation to be used as the literal filename · Issue #9475 · PowerShell/PowerShell
X Title: Passing an escaped wildcard expression to -Path in file-creating cmdlets causes the escaped representation to be used as the literal filename · Issue #9475 · PowerShell/PowerShell
Description: Note: This seems to affect all file-creating cmdlets - including > and >> - with the laudable exception of Set-Content and Add-Content. Conceptually related: #7999 Say you want to create a file literally named file[1].txt. In order to su...
Open Graph Description: Note: This seems to affect all file-creating cmdlets - including > and >> - with the laudable exception of Set-Content and Add-Content. Conceptually related: #7999 Say you want to create a file lit...
X Description: Note: This seems to affect all file-creating cmdlets - including > and >> - with the laudable exception of Set-Content and Add-Content. Conceptually related: #7999 Say you want to create a...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/9475
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Passing an escaped wildcard expression to -Path in file-creating cmdlets causes the escaped representation to be used as the literal filename","articleBody":"Note: This seems to affect all file-creating cmdlets - including `\u003e` and `\u003e\u003e` - with the laudable exception of `Set-Content` and `Add-Content`.\r\n\r\nConceptually related: #7999\r\n\r\nSay you want to create a file literally named `file[1].txt`.\r\n\r\nIn order to successfully pass this name to a `-Path` parameter (or `-FilePath` for `-OutFile`), it must be escaped as `` file`[1`].txt ``, because `-Path` parameters interpret their arguments as wildcard expressions.\r\n\r\nWhile such an escaped path is _accepted_, the problem is that _it isn't retranslated into its literal equivalent on file creation_, resulting in the _escaped_ representation being used as the filename; in the example above, you end up with a file literally named `` file`[1`].txt `` instead of the intended `` file[1].txt ``\r\n\r\nThis problem can generally be avoided by passing the filename to the `-LiteralPath` parameter instead, but that is not yet always an option - see #3174 - and, of course, the bug is worth fixing either way.\r\n\r\n# Steps to reproduce\r\n\r\nRun the following Pester tests:\r\n\r\n```powershell\r\nDescribe '-Path file-creation test' {\r\n BeforeAll { Push-Location TestDrive:\\ }\r\n AfterAll { Pop-Location }\r\n It \"Escaped wildcard paths are created as their literal equivalents\" {\r\n 'hi' | Out-File -FilePath 'file`[1`].txt'\r\n Test-Path -LiteralPath 'file[1].txt' | Should -Be $true\r\n Test-Path -LiteralPath 'file`[1`].txt' | Should -Be $false\r\n }\r\n}\r\n```\r\n\r\n# Expected behavior\r\n\r\nThe tests should pass.\r\n\r\n# Actual behavior\r\n\r\nThe tests fail, because the actual name of the file created is literally `` file`[1`].txt ``, i.e., the _escaped_ name.\r\n\r\n# Environment data\r\n\r\n```none\r\nPowerShell Core 6.2.0 / Windows PowerShell v5.1\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2019-04-26T18:23:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/9475/PowerShell/issues/9475"}
| 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:101e2339-0a37-11f3-3b96-d31809acbea8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CA6:164B5:6F680B:942E91:6A582E48 |
| html-safe-nonce | e58869f5f8bda614f5f9aa35a390a1d67b015fe6d006087fefd155072692fab7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0E2OjE2NEI1OjZGNjgwQjo5NDJFOTE6NkE1ODJFNDgiLCJ2aXNpdG9yX2lkIjoiNzAyMTQ5ODExODgwMzMwNDAwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6bae8c56ec5e1e714bfcec53176b2ae056a5f4181b94c11ca97d654b7686672a |
| hovercard-subject-tag | issue:437791671 |
| 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/9475/issue_layout |
| twitter:image | https://opengraph.githubassets.com/25f2139ec9eac94a940cb4fedff98dbf39aad0ad187803b05a6149f558df459a/PowerShell/PowerShell/issues/9475 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/25f2139ec9eac94a940cb4fedff98dbf39aad0ad187803b05a6149f558df459a/PowerShell/PowerShell/issues/9475 |
| og:image:alt | Note: This seems to affect all file-creating cmdlets - including > and >> - with the laudable exception of Set-Content and Add-Content. Conceptually related: #7999 Say you want to create a file lit... |
| 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