Title: -replace operator stringifies its LHS operand culture-sensitively · Issue #10948 · PowerShell/PowerShell · GitHub
Open Graph Title: -replace operator stringifies its LHS operand culture-sensitively · Issue #10948 · PowerShell/PowerShell
X Title: -replace operator stringifies its LHS operand culture-sensitively · Issue #10948 · PowerShell/PowerShell
Description: In many contexts PowerShell uses the invariant culture for string operations for predictable operation irrespective of the session's current culture. For instance, "$(1.2)" (string interpolation in expandable strings) yields '1.2' even i...
Open Graph Description: In many contexts PowerShell uses the invariant culture for string operations for predictable operation irrespective of the session's current culture. For instance, "$(1.2)" (string interpolation in...
X Description: In many contexts PowerShell uses the invariant culture for string operations for predictable operation irrespective of the session's current culture. For instance, "$(1.2)" (string in...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/10948
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"-replace operator stringifies its LHS operand culture-sensitively","articleBody":"In many contexts PowerShell uses the invariant culture for string operations for predictable operation irrespective of the session's current culture.\r\n\r\nFor instance, `\"$(1.2)\"` (string interpolation in expandable strings) yields `'1.2'` even in cultures that use `,`, not `.` as the decimal mark, and cast to numeric types (e.g., `[double] '1.2'`) are similarly culture-invariant.\r\n\r\nThe `-split` and `-replace` operators implicitly convert their LHS operands to strings, if they aren't, but while `-split` commendable uses the culture-invariant conversion (as in expandable strings), \r\n**`-replace` is unexpectedly culture-sensitive**\r\n\r\n# Steps to reproduce\r\n\r\n```powershell\r\nDescribe \"Culture-invariance tests for -split and -replace\" {\r\n BeforeAll {\r\n $prevCulture = [cultureinfo]::CurrentCulture\r\n [cultureinfo]::CurrentCulture = 'fr' # The French culture uses \",\" as the decimal mark.\r\n }\r\n It \"-skip: LHS stringification is not culture-sensitive\" {\r\n 1.2 -split ',' | Should -Be '1.2'\r\n }\r\n It \"-replace: LHS stringification is not culture-sensitive\" {\r\n 1.2 -replace ',' | Should -Be '1.2'\r\n }\r\n AfterAll {\r\n [cultureinfo]::CurrentCulture = $prevCulture\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 `-replace` test fails:\r\n\r\n```none\r\n Expected: '1.2'\r\n But was: '12'\r\n```\r\n\r\nThat is, `1.2` was unexpectedly stringified culture-_sensitively_, as `'1,2'`.\r\n\r\n# Environment data\r\n\r\n```none\r\nPowerShell Core 7.0.0-preview.5\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2019-10-30T20:42:09Z","url":"https://github.com/PowerShell/PowerShell/issues/10948"}
| 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:06ee6ea1-2cd0-16e5-80b5-7bd89872ee5d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E0DE:28C4B0:18AD8A:22A486:6AFD5008 |
| html-safe-nonce | 4d2f69c0fef166458c31074e3b2e77cc215e66cdedd6c44faf62aee36eadcca9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMERFOjI4QzRCMDoxOEFEOEE6MjJBNDg2OjZBRkQ1MDA4IiwidmlzaXRvcl9pZCI6IjgxMjY2NDc0Nzk1NzY2NDU2NDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c84a615266b95ff04f5a342e58a61b25eeaf2197ddc98060943bcbbea4cddb1f |
| hovercard-subject-tag | issue:514969167 |
| 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/10948/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c16b935693e562eeef61a3c96e7d2407ca639eb55c3088641a8f2ecb5d0745de/PowerShell/PowerShell/issues/10948 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c16b935693e562eeef61a3c96e7d2407ca639eb55c3088641a8f2ecb5d0745de/PowerShell/PowerShell/issues/10948 |
| og:image:alt | In many contexts PowerShell uses the invariant culture for string operations for predictable operation irrespective of the session's current culture. For instance, "$(1.2)" (string interpolation in... |
| 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 | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| 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 | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width