-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix Creating Undermined Culture #115919
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
Fix Creating Undermined Culture #115919
Conversation
Tagging subscribers to this area: @dotnet/area-system-globalization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that the ICU-normalized “und” (undetermined) culture maps to the invariant culture and prevents duplicate caching.
- Added a
UndeterminedCultureTest
to verify name normalization and caching behavior - Updated
GetCultureInfo
to only insert new entries if absent - Modified
NormalizeCultureName
to treat empty ICU results (like “und”) as invariant
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/libraries/System.Runtime/tests/System.Globalization.Tests/CultureInfo/CultureInfoCtor.cs | Added a test for “und” normalization and caching of invariant culture |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs | Changed cache insertion to TryAdd so existing entries aren’t overwritten |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs | Treated empty-window-name ICU results as invariant culture |
Comments suppressed due to low confidence (2)
src/libraries/System.Runtime/tests/System.Globalization.Tests/CultureInfo/CultureInfoCtor.cs:425
- Consider adding an assertion that
undetermined1
references the same instance as the invariant culture (e.g.,Assert.Same(invariant1, undetermined1)
) to verify caching behavior for "und".
CultureInfo undetermined1 = CultureInfo.GetCultureInfo("und");
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs:1053
- You can simplify cache insertion by using
nameTable.GetOrAdd(name, result)
instead of manual lock andTryAdd
, reducing code complexity.
lock (nameTable)
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
…CultureData.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple small comments. Otherwise seems reasonable.
/ba-g build timeout and unrelated |
Fixes #115913
The culture name
und
(undetermined) is a special case recognized by ICU. It typically gets normalized to an empty string, which maps to the invariant culture. The fix here ensures thatund
is handled consistently with the invariant culture and prevents overwriting the cached invariant culture entry when creating a culture forund
.