[iOS] IndexOf on Apple mobile doesn't handle surrogate pairs the same as ICU does
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
Consider case:
```
string s = "\uD800\uDC00";
Console.WriteLine($"Valid Surrogate: Index Of: {s.IndexOf("\uDC00")}"); // Should print -1
```
But on iOS, this returns 1, which is incorrect.
Some possible test cases to add to `CompareInfoTests.IndexOf.cs` are
```
// Two high surrogates in a row - each treated as separate code unit
yield return new object[] { s_invariantCompare, "a$\uD800\uD801b", "\uD801", 0, 5, CompareOptions.IgnoreSymbols, 3, 1 };
// High surrogate followed by regular char
yield return new object[] { s_invariantCompare, "a$\uD800xb", "x", 0, 5, CompareOptions.IgnoreSymbols, 3, 1 };
// Malformed: searching for first high surrogate
yield return new object[] { s_invariantCompare, "$\uD800\uD801!", "\uD800", 0, 4, CompareOptions.IgnoreSymbols, 1, 1 };
// Malformed surrogates without IgnoreSymbols
yield return new object[] { s_invariantCompare, "\uD800\uD801", "\uD801", 0, 2, CompareOptions.None, 1, 1 };
// Valid surrogate pair - low surrogate should NOT be found as it's part of the pair
yield return new object[] { s_invariantCompare, "\uD800\uDC00", "\uDC00", 0, 2, CompareOptions.None, -1, 0 };
// Low surrogate at the end after valid pair
yield return new object[] { s_invariantCompare, "\uD800\uDC00\uD801", "\uD801", 0, 3, CompareOptions.None, 2, 1 };
```
After this behavior is corrected, we should verify the logic for `IgnoreSymbols` is working as expected with surrogate pairs as well:
https://github.com/dotnet/runtime/blob/51c8f3c71a05c440efdd7ad49189a56cb3f53afe/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs#L130-L144
and
https://github.com/dotnet/runtime/blob/51c8f3c71a05c440efdd7ad49189a56cb3f53afe/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.iOS.cs#L327-L335
Contributor guide
Assessment
This issue has not been assessed yet.