Title: Bug fixes needed to support interchangeable use of "/" (forward slash) and "\" (backslash) in file paths on Unix-like platforms · Issue #9244 · PowerShell/PowerShell · GitHub
Open Graph Title: Bug fixes needed to support interchangeable use of "/" (forward slash) and "\" (backslash) in file paths on Unix-like platforms · Issue #9244 · PowerShell/PowerShell
X Title: Bug fixes needed to support interchangeable use of "/" (forward slash) and "\" (backslash) in file paths on Unix-like platforms · Issue #9244 · PowerShell/PowerShell
Description: Note: This issue is meant to supersede #8158 and #6833 and #10682 . From the committee decision at #8587 (comment): Filesystem accepting both / and \ on all systems is an explicit cross platform experience decision for PowerShell. Given ...
Open Graph Description: Note: This issue is meant to supersede #8158 and #6833 and #10682 . From the committee decision at #8587 (comment): Filesystem accepting both / and \ on all systems is an explicit cross platform ex...
X Description: Note: This issue is meant to supersede #8158 and #6833 and #10682 . From the committee decision at #8587 (comment): Filesystem accepting both / and \ on all systems is an explicit cross platform ex...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/9244
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug fixes needed to support interchangeable use of \"/\" (forward slash) and \"\\\" (backslash) in file paths on Unix-like platforms","articleBody":"Note: \r\n* This issue is meant to supersede #8158 and #6833 and #10682 .\r\n\r\n---\r\n\r\nFrom the committee decision at https://github.com/PowerShell/PowerShell/pull/8587#issuecomment-477375667:\r\n\r\n> Filesystem accepting both `/` and `\\` on all systems is an explicit cross platform experience decision for PowerShell.\r\n\r\nGiven that it's currently impossible on Unix-like platforms - where `\\` is a legal filename character - to access or wildcard-match filenames with embedded `\\` chars., the following fixes are needed:\r\n\r\n* Wildcard matching must able to match `\\` chars., namely via `?` or `*` or `[\\]`.\r\n * Note that inside `[...]`, `\\` shouldn't require escaping, analogous to `[.]` matching a _literal_ `.` in a regex. \r\n\r\n* `-Path` and `-LiteralPath` arguments must support `` ` ``-escaping of `\\` chars. to request their literal treatment.\r\n\r\n* The `.PS*` provider property values (`.PSPath`, `.PSParentPath`, `.PSChildName`) must reflect the _escaped_ path.\r\n\r\n* To-native-path conversions such as with `Convert-Path` must remove the escaping.\r\n\r\n* Native globbing must not break if a wildcard pattern happens to match a filename that contains `\\`.\r\n\r\nNote: \r\n\r\n* Even the above doesn't address the awkwardness of the - unescaped - `.FullName` value of `System.IO.FileSystemInfo` _not_ being directly usable with the filesystem provider; e.g., with the provider bug fixed, something like `(Get-ChildItem \"$HOME/a\\b\").FullName` would return something like `/Users/jdoe/a\\b` - unescaped.\r\n\r\n* Similarly, native paths from outside sources with embedded `\\` - e.g., read from a file - will break in PowerShell commands, unless explicit escaping with ``-replace '`', '\\`'`` is performed.\r\n\r\n* `` ` `` as the escape char. means that it requires _doubling_ inside `\"...\"` and therefore also in _unquoted_ arguments in order to be passed through; i.e., the following calls would be equivalent and match a file literally named `a\\b`:\r\n\r\n```powershell\r\nGet-Item 'a`\\b'\r\nGet-Item \"a``\\b\" # !! \r\nGet-Item a``\\b # !! implicitly treated like a \"...\" string\r\n```\r\n\r\n* Handling `` ` `` instances that precede a char. _other_ than `\\` gets quite tricky:\r\n\r\n * Literal paths: So as not to break the existing ability to match `` ` `` literally in paths, `` ` `` must be special only before `\\` and before `` ` `` itself. This follows the model of `\\` use in double-quoted strings in Bash, but introduces the awkwardness of needing to interpret `` 'a`b' `` and `` 'a``b' `` the same (similar to how `\"a\\b\"` and `\"a\\\\b\"` are equal in Bash).\r\n\r\n * Wildcard paths: Wildcard matching itself _always_ requires doubling of `` ` `` for literal use; e.g., \r\n``'a`b' -like 'a`b'`` is `$false`, and only ```'a`b' -like 'a``b'``` is `$true` (edge case: `` 'a`' -like 'a`' `` is also `$true` - the trailing syntactically incomplete use of `` ` `` is interpreted as a literal).\r\n * However, use of wildcards _with the filesystem provider_:\r\n * currently makes `` Get-Item -Path 'a`b' `` match a file literally named `` a`b ``, even though it shouldn't.\r\n * currently doesn't find a match with `` Get-Item -Path 'a``b' `` and neither with `` Get-Item -Path 'a``?' ``, even though it should.\r\n * In other words: wildcard handling by the filesystem provider is currently _broken_ - this may be related to #7999.\r\n * While _falling back_ to literal interpretation is perhaps useful, especially given that `-Path` is the default parameter, this should be fixed, separately.\r\n\r\n# Steps to reproduce\r\n\r\nOn macOS or Linux, run the following Pester tests:\r\n\r\n```powershell\r\n# Note: -Skip isn't yet supported at the level of Describe and Context blocks.\r\n# See https://github.com/pester/Pester/issues/442\r\nif ($env:OS -eq 'Windows_NT') {\r\n Write-Warning \"Tests apply to Unix-like platforms only\" }\r\nelse {\r\n Describe \"Support for backslashes in Unix filenames\" {\r\n BeforeAll {\r\n Push-Location TestDrive:\\\r\n # File with literal backslash in its name.\r\n touch 'a\\b'\r\n $nativePath = ($PWD.ProviderPath -replace '/$') + '/' + 'a\\b'\r\n $escapedName = 'a`\\b'\r\n $escapedPath = ((Get-Item .).PSPath -replace '/$') + '/' + $escapedName\r\n # File with literal backtick in its name.\r\n touch 'a`b'\r\n }\r\n It \"Backslashes can be matched with wildcards\" {\r\n (Get-Item -Path 'a?b').Name | Should -BeExactly 'a\\b'\r\n (Get-Item -Path 'a*b').Name | Should -BeExactly 'a\\b'\r\n (Get-Item -Path 'a[\\]b').Name | Should -BeExactly 'a\\b'\r\n }\r\n It \"Backtick-escaped backslashes match literal ones in filenames\" {\r\n (Get-Item -Path 'a`\\b').Name | Should -BeExactly 'a\\b'\r\n (Get-Item -LiteralPath 'a`\\b').Name | Should -BeExactly 'a\\b'\r\n }\r\n It \"Backticks not preceding a backslash or backtick are literals in literal paths\" {\r\n (Get-Item -LiteralPath 'a`b').Name | Should -BeExactly 'a`b'\r\n }\r\n It \"Doubled backticks are also literals in literal paths\" {\r\n (Get-Item -LiteralPath 'a``b').Name | Should -BeExactly 'a`b'\r\n }\r\n It \"Backtick-escaped backticks must be recognized as a literal backtick in wildcard paths\" {\r\n (Get-Item -Path 'a``?').Name | Should -BeExactly 'a`b'\r\n }\r\n It \"Provider properties contain escaped paths\" {\r\n (Get-Item -LiteralPath 'a`\\b').PSChildName | Should -BeExactly $escapedName\r\n (Get-Item -LiteralPath 'a`\\b').PSPath | Should -BeExactly $escapedPath\r\n }\r\n It \"Convert-Path removes the PS-specific escaping\" {\r\n Get-Item -LiteralPath 'a`\\b' | Convert-Path | Should -BeExactly $nativePath\r\n }\r\n It \"Native globbing doesn't break when a filename with a backslash is among the matches\" {\r\n /bin/echo a* | Should -Not -Match '\\*'\r\n }\r\n AfterAll {\r\n Pop-Location\r\n }\r\n }\r\n\r\n}\r\n```\r\n\r\n# Expected behavior\r\n\r\nAll tests should pass.\r\n\r\n# Actual behavior\r\n\r\nAll tests except \"Backticks not preceding a backslash or backtick are literals in literal paths\" fail.\r\n\r\n# Environment data\r\n\r\n```none\r\nPowerShell Core 6.2.0-rc.1\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2019-03-28T17:10:19Z","url":"https://github.com/PowerShell/PowerShell/issues/9244"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:8656ed17-6054-2ba3-d7e9-ae41082de201 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC52:70C53:62DC9:8AE84:6AFD7A0B |
| html-safe-nonce | 17035e7d5f910280bb7e11a12a0e39c2e35a3bf38972e006aa7af2ec1913278e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzUyOjcwQzUzOjYyREM5OjhBRTg0OjZBRkQ3QTBCIiwidmlzaXRvcl9pZCI6IjgzMTYwNjA3Mjk5NDU3MTcyNTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f3d536bd64f5875eb1f0ecb5a43d0b4dbee2cde25a83080a0636f737f7d7179b |
| hovercard-subject-tag | issue:426611056 |
| 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/9244/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9fed6d97af459955b426bb4dd2bc116789e562a4b1f9f15cb3ebacf385e22519/PowerShell/PowerShell/issues/9244 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9fed6d97af459955b426bb4dd2bc116789e562a4b1f9f15cb3ebacf385e22519/PowerShell/PowerShell/issues/9244 |
| og:image:alt | Note: This issue is meant to supersede #8158 and #6833 and #10682 . From the committee decision at #8587 (comment): Filesystem accepting both / and \ on all systems is an explicit cross platform ex... |
| 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 | 544ff6b59bd215c4609120f6e334dbd0b00d34fb6f8bc03a476f72256998887e |
| 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 | 71c92f8b27ec5e9aa6f6477b4e067a4727fc9edb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width