1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-10 18:11:04 +09:00

Fix span write in InvariantCreateSortKeyOrdinalIgnoreCase (#105344)

This commit is contained in:
xtqqczze 2024-07-24 04:49:10 +01:00 committed by GitHub
parent 7d5fe6a33d
commit a70e8ab165
Signed by: github
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View file

@ -66,10 +66,11 @@ namespace System.Globalization
if (char.IsLowSurrogate(cl))
{
SurrogateCasing.ToUpper(c, cl, out char hr, out char lr);
BinaryPrimitives.WriteUInt16BigEndian(sortKey, hr);
BinaryPrimitives.WriteUInt16BigEndian(sortKey, lr);
i++;
Span<byte> tmp = sortKey.Slice(0, 2 * sizeof(ushort)); // help with bounds check elimination
BinaryPrimitives.WriteUInt16BigEndian(tmp, hr);
BinaryPrimitives.WriteUInt16BigEndian(tmp.Slice(sizeof(ushort)), lr);
sortKey = sortKey.Slice(2 * sizeof(ushort));
i++;
continue;
}
}

View file

@ -773,6 +773,7 @@ namespace System.Globalization.Tests
[InlineData("Hello", CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth, "HELLO")]
[InlineData("Hell\u00F6", CompareOptions.None, "Hell\u00F6")] // U+00F6 = LATIN SMALL LETTER O WITH DIAERESIS
[InlineData("Hell\u00F6", CompareOptions.IgnoreCase, "HELL\u00D6")]
[InlineData("Hell\uD82A\uDC15", CompareOptions.IgnoreCase, "HELL\uD82A\uDC15")] // U+D82A = High Surrogate; U+DC15 = Low Surrogate
public unsafe void TestSortKey_FromSpan(string input, CompareOptions options, string expected)
{
byte[] expectedOutputBytes = GetExpectedInvariantOrdinalSortKey(expected);