-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StringComparison.OrdinalIgnoreCase
compares "¡a"
and "¡B"
incorrectly
#71018
Comments
Tagging subscribers to this area: @dotnet/area-system-globalization Issue DetailsDescriptionIn But In The Setting (Even if this is the actual result returned by ICU for the comparison--and I'm not sure if that's true or not--it doesn't match this programmer's expectations for what Reproduction StepsProgram.cs: using System;
// prints -1 for prefix <= U+007F, 31 for prefix >= U+0080
string prefix = "\u00A1";
Console.WriteLine(string.Compare($"{prefix}a", $"{prefix}B", StringComparison.OrdinalIgnoreCase)); Compare.csproj <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net48;net5.0;net6.0;net7.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
</Project> Expected behavior
Thus, it is expected that Actual behavior
Regression?Yes. This worked correctly in Known WorkaroundsUse ConfigurationSDKs: 6.0.301; 7.0.100-preview.5.22307.18 Other informationNo response
|
The prefix can be arbitrarily long (e.g., |
@bgrainger thanks for filing the issue. Yes, this is a bug. |
@bgrainger just checking if this issue is a blocker issue for you for using .NET 6.0? I am asking to know if we need to consider porting it to .NET 6.0 or we can just fix it in .NET 7.0? |
No, this isn't strictly a blocker for me. It did break my code's ability to read (using a binary search) some sorted data that was compiled into the assembly as an embedded resource; however, I was able to restore functionality across all .NET versions by recompiling the assembly (and the embedded data) with IMO it is a serious regression to leave unfixed in .NET 6.0. Any code that has sorted data according to |
@bgrainger thanks again for the information. We have decided to wait a little to see if there is a demand or more scenarios broken because of that. We'll keep our eyes open on that. If you came across more data regarding this issue, please share it with us. This can help in deciding in porting the fix. |
Description
In
net5.0
andnet48
on Windows,string.Compare("¡a", "¡B", StringComparison.OrdinalIgnoreCase)
returns a value < 0 (specifically -1).But In
net6.0
andnet7.0
, that expression returns a value > 0 (specifically, 31).The
net5.0
result fulfills the meaning ofStringComparison.OrdinalIgnoreCase
; thenet6.0
result does not.Setting
$env:DOTNET_SYSTEM_GLOBALIZATION_USENLS='true'
restores thenet5.0
behaviour, which indicates that this may be related to #30960?(Even if this is the actual result returned by ICU for the comparison--and I'm not sure if that's true or not--it doesn't match this programmer's expectations for what
StringComparison.OrdinalIgnoreCase
means.)Reproduction Steps
Program.cs:
Compare.csproj
Expected behavior
Per https://docs.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings#ordinal-string-operations:
Thus, it is expected that
¡
will be considered equal in both strings, thena
will be compared toB
and the first string will sort first by an case-insensitive ordinal comparison. That is,"¡a"
sorts before"¡B"
using a case-insensitive ordinal comparison.Actual behavior
"¡a"
sorts after"¡B"
using a case-insensitive ordinal comparison.Regression?
Yes. This worked correctly in
net48
andnet5.0
on Windows and Linux; I have not testednet5.0
and earlier on macOS.Known Workarounds
Use
StringComparison.InvariantCultureIgnoreCase
.Set the
DOTNET_SYSTEM_GLOBALIZATION_USENLS
environment variable totrue
.Configuration
SDKs: 6.0.301; 7.0.100-preview.5.22307.18
Windows 10 19044.1766 x64
Other information
No response
The text was updated successfully, but these errors were encountered: