-
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
string.ToUpperInvariant("μ") gives different results on different platforms #54278
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
https://docs.microsoft.com/en-us/dotnet/core/compatibility/globalization/5.0/icu-globalization-api <ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup> using System;
// Micro Sign
Console.WriteLine(char.ToUpperInvariant('\u00B5')); // U+039C in ICU, U+00B5 in NLS
// Greek Small Letter Mu
Console.WriteLine(char.ToUpperInvariant('\u03BC')); // U+039C in both ICU and NLS |
Tagging subscribers to this area: @tarekgh, @safern Issue DetailsDescriptionWe're using Results from the following GitHub Actions build agents:
I can set up a repo with GitHub Actions to repro this if that's helpful here. Configuration
Regression?Unsure - only noticed when exercising this functionality for the first time. Other informationN/A
|
@tarekgh Here's another example of a use case that could benefit from a first-party "case folding" API, as |
@anthony-c-martin you are using Windows Server 2019 which by default not having the ICU library we depend on. That is why this you may experience the difference. You can try including the ICU in your app when running on Windows Server 2019. You can do that by <ItemGroup>
<PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.6" />
<RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2" />
</ItemGroup> This should help.
Moving forward when users using ICU users should experience consistent results. This is not specific to the casing operation only but for collation operations too. I am not opposing the idea; I am just trying to have the casing and the collation are consistent even for Invariant. That is why I prefer if we expose the case folding as its own APIs and not tie it to invariant. I am closing this issue as we already having issue #20674 tracking the request. @anthony-c-martin feel free to send any more questions if you have any. Thanks for your report. |
Does the |
Yes, it does. |
@tarekgh - do you have any guidance for authors of shared libraries targeting .NET standard? In our scenario, the logic which relies upon We can go and fix the applications we own which depend on this package, but is there a way we can guarantee that any consumer of this package will see consistent behavior? |
@anthony-c-martin could you tell more about your scenario. you mentioned you are hashing JSON blob. Where this blob came from and how you are using the hashing of this blob? |
It's a user-defined document (example here) which is usually either user-authored, or programmatically generated. The API which handles this document is case-insensitive, so we want a means of generating a hash to compare two documents for (case-insensitive) equivalence - mostly for telemetry. We also own some cross-platform client tools which work with templates, so we'd like to ensure we can reliably generate the same hash client-side. The hashing logic we run on the JSON document roughly looks like:
|
Thanks @anthony-c-martin for sharing the details. If you want to always guarantee the exact same casing/hashing between the server and client, you'll need to do one of the following:
|
Description
We're using
string.ToUpperInvariant()
to normalize a JSON blob for case-insensitive hashing, and noticed that if the string contains a "μ", the hash is different across different platforms.Results from the following GitHub Actions build agents:
windows-latest
:string.ToUpperInvariant("μ")
->μ
ubuntu-latest
:string.ToUpperInvariant("μ")
->M
macos-latest
:string.ToUpperInvariant("μ")
->M
I can set up a repo with GitHub Actions to repro this if that's helpful here.
Configuration
net5.0
windows-latest
: https://github.com/actions/virtual-environments/blob/releases/win19/20210608/images/win/Windows2019-Readme.mdubuntu-latest
: https://github.com/actions/virtual-environments/blob/releases/ubuntu20/20210614/images/linux/Ubuntu2004-README.mdmacos-latest
: https://github.com/actions/virtual-environments/blob/releases/macOS-10.15/20210612/images/macos/macos-10.15-Readme.mdRegression?
Unsure - only noticed when exercising this functionality for the first time.
Other information
N/A
The text was updated successfully, but these errors were encountered: