Skip to content

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

Merged
merged 5 commits into from
May 25, 2025
Merged

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented May 23, 2025

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 that und is handled consistently with the invariant culture and prevents overwriting the cached invariant culture entry when creating a culture for und.

@Copilot Copilot AI review requested due to automatic review settings May 23, 2025 01:50
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-globalization
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

@Copilot Copilot AI left a 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 and TryAdd, reducing code complexity.
lock (nameTable)

…CultureData.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@tarekgh tarekgh added this to the 10.0.0 milestone May 23, 2025
Copy link
Member

@ericstj ericstj left a 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.

@tarekgh
Copy link
Member Author

tarekgh commented May 25, 2025

/ba-g build timeout and unrelated

@tarekgh tarekgh merged commit 67a567f into dotnet:main May 25, 2025
139 of 141 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong culture returned from CultureInfo.GetCultureInfo("")
2 participants