You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Compare-Object with [char] instances is unexpectedly case-sensitive by default #17758
If [char] instances were consistently compared case-insensitively to each other and to strings, all of the following commands would output 0.
# OK: [string] vs. [string]
(Compare-Object ('a') ('A')).Count
# OK: [string] vs. [char]
(Compare-Object ('a') ([char] 'A')).Count
# !! BROKEN: [char] vs. [char]
(Compare-Object ([char] 'a') ([char] 'A')).Count
# !! BROKEN: [char] vs. [string]
(Compare-Object ([char] 'a') ('A')).Count
Note that [char] 'a' -eq [char] 'A' is $true (even though with -gt, -lt, ... it is the code points that get compared, resulting in case-sensitive behavior).
#12498 is conceptually related, but would not fix this issue, because use of the IEquatable<T> interface would also result in case-sensitive behavior.
How do chars compare, as chars or as strings? Compare-Object'sCaseSensitive parameter does not affect the result (and this is expected behavior for non strings, IMO). But:
237dmitry: They're not technically compared as strings with -eq (if memory serves, .ToUpperInvariant() is called before comparing), but the intent is clearly the same: compare [char]s case-INsensitively.
Therefore, Compare-Object, which is also built on equality comparison, should behave the same (with -CaseSensitive acting as opt-out).
How do chars compare, as chars or as strings? Compare-Object'sCaseSensitive parameter does not affect the result (and this is expected behavior for non strings, IMO). But:
IEQ might call ToUpper or ToLower on both strings and a chars and compare the result or it might specify the comparison type for strings. My hunch is Compare-Object is only requesting insensitive for strings and not for chars.
Because there is only a -CaseSensitive option for Compare-Object the natural expectation is chars and strings both use case insensitive comparisons by default and only case sensitive when the switch is specified.
Reacted by Michael Klement and Rain Sallow (/u/ta11ow)
microsoft-github-policy-service commented on Nov 15, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Activity
237dmitry commentedon Jul 24, 2022
How do chars compare, as chars or as strings?
Compare-Object'sCaseSensitiveparameter does not affect the result (and this is expected behavior for non strings, IMO). But:mklement0 commentedon Jul 24, 2022
237dmitry: They're not technically compared as strings with
-eq(if memory serves,.ToUpperInvariant()is called before comparing), but the intent is clearly the same: compare[char]s case-INsensitively.Therefore,
Compare-Object, which is also built on equality comparison, should behave the same (with-CaseSensitiveacting as opt-out).237dmitry commentedon Jul 24, 2022
Thanks for the clarification.
jhoneill commentedon Jul 27, 2022
I think
-eqis always-ieqThe char type itself only does case sensitive comparisonsBut string comparisons are case sensitive by default with the option to select culture and case sensitivity.
IEQ might call ToUpper or ToLower on both strings and a chars and compare the result or it might specify the comparison type for strings. My hunch is
Compare-Objectis only requesting insensitive for strings and not for chars.Because there is only a
-CaseSensitiveoption forCompare-Objectthe natural expectation is chars and strings both use case insensitive comparisons by default and only case sensitive when the switch is specified.microsoft-github-policy-service commentedon Nov 15, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 22, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.