Skip to content

Commit

Permalink
Fix string case-insensitive comparisons in Globalization invariant mo…
Browse files Browse the repository at this point in the history
…de (#107311)

Co-authored-by: Tarek Mahmoud Sayed <tarekms@microsoft.com>
  • Loading branch information
github-actions[bot] and tarekgh authored Sep 4, 2024
1 parent d0f3235 commit 31528d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ internal static int CompareStringIgnoreCase(ref char strA, int lengthA, ref char
continue;
}

return (int)codePointA - (int)codePointB;
return (int)aUpper - (int)bUpper;
}

return lengthA - lengthB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,5 +1257,18 @@ private static byte[] GetExpectedInvariantOrdinalSortKey(ReadOnlySpan<char> inpu

return memoryStream.ToArray();
}

[Fact]
public void TestChainStringComparisons()
{
var s1 = "бал";
var s2 = "Бан";
var s3 = "Д";

// If s1 < s2 and s2 < s3, then s1 < s3
Assert.True(string.Compare(s1, s2, StringComparison.OrdinalIgnoreCase) < 0);
Assert.True(string.Compare(s2, s3, StringComparison.OrdinalIgnoreCase) < 0);
Assert.True(string.Compare(s1, s3, StringComparison.OrdinalIgnoreCase) < 0);
}
}
}

0 comments on commit 31528d0

Please sign in to comment.