Title: Comparison operators handle [char] instances inconsistently · Issue #18659 · PowerShell/PowerShell · GitHub
Open Graph Title: Comparison operators handle [char] instances inconsistently · Issue #18659 · PowerShell/PowerShell
X Title: Comparison operators handle [char] instances inconsistently · Issue #18659 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/18659
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Comparison operators handle [char] instances inconsistently","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\n### Steps to reproduce\r\n\r\nFundamentally, as in C#, `[char]` instances are ultimately compared _ordinally_, i.e. by their _code points_ rather than by the linguistic rules oft he invariant culture (which is how [string]` instances are compared).\r\n\r\n* However, only the `-eq` / `-ne` operator honors case-sensitivity / case-insensitivity, as implied by the operator variant chosen; e.g. `-eq` (`-ieq`) for case-_insensitivity_, `-ceq` for case-_sensitivity_.\r\n * If memory serves, case-_insensitivity_ is honored as follows: `.ToUpperInvariant()` is called on both operands, and the resulting code points are then tested for equality.\r\n * As an aside: this can still behave differently from `[string]` comparisons, because linguistic equivalence isn't considered; e.g. (`K` is the KELVIN SIGN, [`U+212A`](http://www.fileformat.info/info/unicode/char/212a)):\r\n * `'k' -eq 'K'` # -> `$true`, because lowercase ASCII 'k' is considered the case-insensitive equivalent of the Kelvin sign.\r\n * `[char] 'k' -eq [char] 'K'` # -> `$false`, because the code points resulting from `.ToUpperVariant()` aren't identical.\r\n\r\n* By contrast, `-gt` / `-ge` and `-lt` / `-le` _ignore_ the requested case-(in)sensitivity, and perform direct code-point comparison.\r\n\r\nThis is a surprising inconsistency, as the following contradictory results show:\r\n\r\n```powershell\r\n[char] 'a' -eq [char] 'A' # -> $true; same as: [int] [char]::ToUpperInvariant('a') -eq [int] [char]::ToUpperInvariant('A')\r\n\r\n[char] 'a' -le [char] 'A' # !! -> $false, because code points were compared as-is and 97 is greater than 65\r\n```\r\n\r\nNote that fixing this consistency would technically be a breaking change, but hopefully falls into [bucket 3](https://github.com/PowerShell/PowerShell/blob/master/docs/dev-process/breaking-change-contract.md#bucket-3-unlikely-grey-area).\r\n\r\n### Expected behavior\r\n\r\n```console\r\nTrue\r\nTrue\r\n```\r\n\r\n\r\n### Actual behavior\r\n\r\n```console\r\nTrue\r\nFalse\r\n```\r\n\r\n\r\n### Error details\r\n\r\n_No response_\r\n\r\n### Environment data\r\n\r\n```powershell\r\nPowerShell Core 7.3.0\r\n```\r\n\r\n\r\n### Visuals\r\n\r\n_No response_","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2022-11-24T18:17:07Z","url":"https://github.com/PowerShell/PowerShell/issues/18659"}
| 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:7f0ba224-0909-91b2-1edf-8ba924dc7e6d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E4E:E9A8B:2C49BAB:3E1EF21:6AFD6B23 |
| html-safe-nonce | 5e2d38d3734fe49ed29660b97469419a689c469dd198cfbe78de4925749ad4fb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTRFOkU5QThCOjJDNDlCQUI6M0UxRUYyMTo2QUZENkIyMyIsInZpc2l0b3JfaWQiOiI3Nzg3NTMyODYwNjM3NjcwMTc5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8fa93dd59d6c9f26045a140da9d57324d43176ed5e24339c1fec6ba2cb48b4b0 |
| hovercard-subject-tag | issue:1463690730 |
| 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/18659/issue_layout |
| twitter:image | https://opengraph.githubassets.com/102d8aa660e78136da9ed610c48701dc75fc13cf00f6bc6483f25ca935494ee8/PowerShell/PowerShell/issues/18659 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/102d8aa660e78136da9ed610c48701dc75fc13cf00f6bc6483f25ca935494ee8/PowerShell/PowerShell/issues/18659 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| 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 | 9985ca2e21b59673104d4d830d4afeb946c67f248f273ab2e824c31c8db46e4a |
| 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 | 0db9e8d463c3f4540570e6ad3c501a06db9dc02a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width