-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix span write in InvariantCreateSortKeyOrdinalIgnoreCase
#105344
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 span write in InvariantCreateSortKeyOrdinalIgnoreCase
#105344
Conversation
Tagging subscribers to this area: @dotnet/area-system-globalization |
@xtqqczze Thanks for your contribution. At the moment, we are only accepting critical changes for the .NET 9.0 release. Nice-to-have fixes will need to wait until we fork the main branch to accept changes for future releases. Since this PR is already a draft, we can keep it open for a while until the fork. Alternatively, you can close it and reopen it later after the fork. I wanted to set the expectation in case you notice no traction on the PR. |
InvariantCreateSortKeyOrdinalIgnoreCase
InvariantCreateSortKeyOrdinalIgnoreCase
@tarekgh This fixes a probable bug. |
@xtqqczze I'll take a look. Thanks! |
@xtqqczze could you please explain more why you think there is a bug?
|
@tarekgh When writing to the span, we overwrite the high surrogate with the low surrogate: runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Invariant.cs Lines 69 to 70 in f644110
This is unexpected, at least. |
Can you share a test that fails because of the issue? |
I see. I was confused with the line
This is a good idea to add a test for this case. |
Here is the code can be used in the test case: CultureInfo culture = CultureInfo.InvariantCulture;
var sortKey = culture.CompareInfo.GetSortKey("\uD800\uDC00", CompareOptions.IgnoreCase);
foreach (var b in sortKey.KeyData)
{
Console.Write($"{b:X2} "); // should produce something like D8-00-DC-00
} We need to add the test to https://github.com/dotnet/runtime/tree/main/src/libraries/System.Runtime/tests/System.Globalization.Tests/Invariant |
This is technically a breaking change to GetSortKey(ReadOnlySpan, Span, CompareOptions) in the Bucket 3: Unlikely Grey Area category. |
I am not worried about that. The issue is specific for Invariant Globalization mode with Surrogate pairs. Sort keys usually interesting with the full globalization support. |
src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Invariant.cs
Show resolved
Hide resolved
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.
Thanks @xtqqczze!
InvariantCreateSortKeyOrdinalIgnoreCase
InvariantCreateSortKeyOrdinalIgnoreCase
/ba-g failures are known |
cc: @tarekgh
Existing logic appears to be incorrect: