-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix string case-insensitive comparisons in Globalization invariant mode #107268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix string case-insensitive comparisons in Globalization invariant mode #107268
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-globalization |
|
@ericstj I am willing to port this fix to 9.0 release, the comment #106828 (comment) is helpful why I want to do that. The change is small and safe with low risk. |
| } | ||
|
|
||
| return (int)codePointA - (int)codePointB; | ||
| return (int)aUpper - (int)bUpper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised we didn't have cases where this returned the wrong result entirely, for instance when comparing a single upper case to lower case. Do we need more test cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case scoped to the globalization invariant mode. The test I added here should be good enough to catch the cases we need to fix.
Note, we have the right implementation in the other places, like
| return currentA - currentB; |
and
runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs
Line 231 in 46c9a4f
| return aUpper - bUpper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just imagining that it might give the wrong answers (let alone ordering) for things like:
a B -> 97 - 65 = 32 <-- incorrect
A b -> 65 - 98 = -33
A B -> 65 - 66 = -1
And I was surprised we didn't have a theory test somewhere for such basic comparisons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I understand what you are saying but does it really matter much testing single character string or a string with multiple characters as the case I added? if you think this is worth adding I can do it.
|
/backport to release/9.0 |
|
Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10689249576 |
This issue addressing #106828.
In Globalization invariant mode when comparing string with case insensitive option, should satisfy the rule: if s1 < s2 and s2 < s3, then s1 < s3. The change here is fixing the string comparison to ensure this rule.