Skip to content

Commit 68d1dfc

Browse files
authored
Fix neutral cultures created with the underscore (#87411)
1 parent 70af30f commit 68d1dfc

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

src/libraries/System.Globalization/tests/CultureInfo/CultureInfoCtor.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,17 +452,12 @@ public void TestCreationWithMangledSortName(string cultureName, string expectedC
452452
Assert.Equal(expectedSortName, ci.CompareInfo.Name);
453453
}
454454

455-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization))]
456-
public void TestNeutralCultureWithCollationName()
457-
{
458-
Assert.Throws<CultureNotFoundException>(() => CultureInfo.GetCultureInfo("zh-u-co-zhuyin"));
459-
Assert.Throws<CultureNotFoundException>(() => CultureInfo.GetCultureInfo("de-u-co-phonebk"));
460-
}
461-
462455
[InlineData("xx-u-XX", "xx-u-xx")]
463456
[InlineData("xx-u-XX-u-yy", "xx-u-xx-u-yy")]
464457
[InlineData("xx-t-ja-JP", "xx-t-ja-jp")]
465458
[InlineData("qps-plocm", "qps-PLOCM")] // ICU normalize this name to "qps--plocm" which we normalize it back to "qps-plocm"
459+
[InlineData("zh_CN", "zh_cn")]
460+
[InlineData("km_KH", "km_kh")]
466461
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization))]
467462
public void TestCreationWithICUNormalizedNames(string cultureName, string expectedCultureName)
468463
{

src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,9 @@ private bool InitIcuCultureDataCore()
138138
_bNeutral = TwoLetterISOCountryName.Length == 0;
139139
_sSpecificCulture = _bNeutral ? IcuLocaleData.GetSpecificCultureName(_sRealName) : _sRealName;
140140

141-
if (_bNeutral && collationStart > 0)
142-
{
143-
return false; // neutral cultures cannot have collation
144-
}
145-
146141
// Remove the sort from sName unless custom culture
147-
_sName = collationStart < 0 ? _sRealName : _sRealName.Substring(0, collationStart);
142+
// To ensure compatibility, it is necessary to allow the creation of cultures like zh_CN (using ICU notation) in the case of _bNeutral.
143+
_sName = collationStart < 0 || _bNeutral ? _sRealName : _sRealName.Substring(0, collationStart);
148144

149145
return true;
150146
}

0 commit comments

Comments
 (0)