Repository navigation
Closed
Labels
PowerShell-Docs neededThe PR was reviewed and a PowerShell Docs update is neededResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimeWG-Languageparser, language semantics
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 reproduce
Fundamentally, 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).
-
However, only the
-eq/-neoperator honors case-sensitivity / case-insensitivity, as implied by the operator variant chosen; e.g.-eq(-ieq) for case-insensitivity,-ceqfor case-sensitivity.- 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. - As an aside: this can still behave differently from
[string]comparisons, because linguistic equivalence isn't considered; e.g. (Kis the KELVIN SIGN,U+212A):'k' -eq 'K'# ->$true, because lowercase ASCII 'k' is considered the case-insensitive equivalent of the Kelvin sign.[char] 'k' -eq [char] 'K'# ->$false, because the code points resulting from.ToUpperVariant()aren't identical.
- If memory serves, case-insensitivity is honored as follows:
-
By contrast,
-gt/-geand-lt/-leignore the requested case-(in)sensitivity, and perform direct code-point comparison.
This is a surprising inconsistency, as the following contradictory results show:
[char] 'a' -eq [char] 'A' # -> $true; same as: [int] [char]::ToUpperInvariant('a') -eq [int] [char]::ToUpperInvariant('A')
[char] 'a' -le [char] 'A' # !! -> $false, because code points were compared as-is and 97 is greater than 65Note that fixing this consistency would technically be a breaking change, but hopefully falls into bucket 3.
Expected behavior
True
TrueActual behavior
True
FalseError details
No response
Environment data
PowerShell Core 7.3.0Visuals
No response
Metadata
Metadata
Assignees
Labels
PowerShell-Docs neededThe PR was reviewed and a PowerShell Docs update is neededResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimeWG-Languageparser, language semantics
Activity
microsoft-github-policy-service commentedon Jan 21, 2024
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.