Skip to content

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 AI review requested due to automatic review settings May 23, 2025 01:50
@dotnet-policy-service
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 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
@github-actions github-actions bot locked and limited conversation to collaborators Jun 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong culture returned from CultureInfo.GetCultureInfo("")

2 participants