Fix Creating Undermined Culture#115919
Merged
tarekgh merged 5 commits intodotnet:mainfrom May 25, 2025
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-globalization |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that the ICU-normalized “und” (undetermined) culture maps to the invariant culture and prevents duplicate caching.
- Added a
UndeterminedCultureTestto verify name normalization and caching behavior - Updated
GetCultureInfoto only insert new entries if absent - Modified
NormalizeCultureNameto 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
undetermined1references 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 <[email protected]>
This was referenced May 23, 2025
ericstj
reviewed
May 23, 2025
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
ericstj
reviewed
May 23, 2025
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Show resolved
Hide resolved
ericstj
approved these changes
May 23, 2025
Member
ericstj
left a comment
There was a problem hiding this comment.
Just a couple small comments. Otherwise seems reasonable.
Member
Author
|
/ba-g build timeout and unrelated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thatundis handled consistently with the invariant culture and prevents overwriting the cached invariant culture entry when creating a culture forund.