String comparisons with the CompareOptions.StringSort value produce incorrect results under .NET 5 and later #102579
Labels
area-System.Globalization
documentation
Documentation bug or enhancement, does not impact product or test code
help wanted
[up-for-grabs] Good issue for external contributors
Milestone
Description
When comparing strings,
CompareOptions.StringSort
should apply low sort weights to hyphens and other non-alphanumeric characters. This works in .NET Framework projects. In .NET 5 and later, however, the weightings are not applied and the results of sorting withCompareOptions.StringSort
are the same as whenCompareOptions.None
is chosen.Note: I am using the default ICU Unicode processing for .NET 5+ testing.
Reproduction Steps
This code is adapted from the
CompareOptions Enum
documentation page here. The word list has been copied verbatim.DotNetFiddle for the code here.
Expected behavior
The
CompareOptions.StringSort
should apply a correct weighted ordering to the unordered collection of strings. The results are correct in .NET Framework 4.7.2 and Roslyn 4.8:Actual behavior
In .NET 5 and later,
CompareOptions.StringSort
is incorrect, producing the same results asCompareOptions.None
:Regression?
According to testing on dotnetfiddle.net, the correct results were produced in .NET Framework 4.7.2 and Roslyn 4.8. .NET 5 and later produce the incorrect sort order.
Known Workarounds
A potential workaround may be to switch from ICU to NLS, but I have not tested this.
Configuration
My system:
I don't think the issue is specific to my OS or architecture, as the same problem can be seen via dotnetfiddle.
Other information
No response
The text was updated successfully, but these errors were encountered: