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
CompareInfo.LastIndexOf does not handle zero-weight sequences correctly on ICU #44439
varci=CultureInfo.InvariantCulture.CompareInfo;Console.WriteLine(ci.LastIndexOf("hello",""));// Prints 5 (correct)Console.WriteLine(ci.LastIndexOf("hello","\0"));// Prints 4, but correct answer is 5Console.WriteLine(ci.LastIndexOf("hello","\u200D"));// Prints 4, but correct answer is 5
And net5.0 on NLS:
varci=CultureInfo.InvariantCulture.CompareInfo;Console.WriteLine(ci.LastIndexOf("hello",""));// Prints 5 (correct)Console.WriteLine(ci.LastIndexOf("hello","\0"));// Prints -1 (correct, null is not weightless in NLS)Console.WriteLine(ci.LastIndexOf("hello","\u200D"));// Prints 5 (correct)
It's possible we have an off-by-one error somewhere in our ICU glue.
The reason all of these methods should return 5 is that "", "\0", and "\u200D" are all equivalent zero-weight strings, and zero-weight strings always trivially exist as a suffix of all possible substrings. (In NLS, the null character U+0000 is not weightless, hence the return value of -1 is correct in that scenario.)
Activity