[release/6.0] Fix calling NLS with Cultures has alternative sort names (#62155)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Wed, 15 Dec 2021 18:41:04 +0000 (12:41 -0600)
committerGitHub <noreply@github.com>
Wed, 15 Dec 2021 18:41:04 +0000 (12:41 -0600)
* Fix calling NLS with Cultures has alternative sort names

* Exclude the test for the browser

* Update src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Nls.cs

Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
* Fix test typo

Co-authored-by: Tarek Mahmoud Sayed <tarekms@microsoft.com>
Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Nls.cs

index eae275b..c36ba96 100644 (file)
@@ -287,7 +287,7 @@ namespace System.Globalization.Tests
                 }
                 yield return new object[] { cultureName, "\u0130", "i" };
                 yield return new object[] { cultureName, "i", "i" };
-                
+
             }
 
             // ICU has special tailoring for the en-US-POSIX locale which treats "i" and "I" as different letters
@@ -478,5 +478,13 @@ namespace System.Globalization.Tests
         {
             Assert.Equal(expected, new CultureInfo(name).TextInfo.ToString());
         }
+
+        [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
+        [InlineData("es-ES")]
+        [InlineData("es-ES_tradnl")]
+        public void TestAsciiCodePageWithCulturesWithAlternativeSortNames(string cultureName)
+        {
+            Assert.Equal(1252, CultureInfo.GetCultureInfo(cultureName).TextInfo.ANSICodePage);
+        }
     }
 }
index be1b108..12f289c 100644 (file)
@@ -47,8 +47,8 @@ namespace System.Globalization
         private string NlsGetLocaleInfo(LocaleStringData type)
         {
             Debug.Assert(ShouldUseUserOverrideNlsData);
-            Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfo] Expected _sWindowsName to be populated by already");
-            return NlsGetLocaleInfo(_sWindowsName, type);
+            Debug.Assert(_sRealName != null, "[CultureData.DoGetLocaleInfo] Expected _sRealName to be populated by already");
+            return NlsGetLocaleInfo(_sRealName, type);
         }
 
         // For LOCALE_SPARENT we need the option of using the "real" name (forcing neutral names) instead of the
@@ -74,15 +74,15 @@ namespace System.Globalization
 
             // Ask OS for data, note that we presume it returns success, so we have to know that
             // sWindowsName is valid before calling.
-            Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
-            return GetLocaleInfoExInt(_sWindowsName, lctype);
+            Debug.Assert(_sRealName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sRealName to be populated already");
+            return GetLocaleInfoExInt(_sRealName, lctype);
         }
 
         private int[] NlsGetLocaleInfo(LocaleGroupingData type)
         {
             Debug.Assert(ShouldUseUserOverrideNlsData);
-            Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
-            return ConvertWin32GroupString(GetLocaleInfoFromLCType(_sWindowsName, (uint)type, _bUseOverrides));
+            Debug.Assert(_sRealName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sRealName to be populated by already");
+            return ConvertWin32GroupString(GetLocaleInfoFromLCType(_sRealName, (uint)type, _bUseOverrides));
         }
 
         internal static bool NlsIsEnsurePredefinedLocaleName(string name)
@@ -94,16 +94,16 @@ namespace System.Globalization
         private string? NlsGetTimeFormatString()
         {
             Debug.Assert(ShouldUseUserOverrideNlsData);
-            Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
-            return ReescapeWin32String(GetLocaleInfoFromLCType(_sWindowsName, Interop.Kernel32.LOCALE_STIMEFORMAT, _bUseOverrides));
+            Debug.Assert(_sRealName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sRealName to be populated by already");
+            return ReescapeWin32String(GetLocaleInfoFromLCType(_sRealName, Interop.Kernel32.LOCALE_STIMEFORMAT, _bUseOverrides));
         }
 
         private int NlsGetFirstDayOfWeek()
         {
             Debug.Assert(ShouldUseUserOverrideNlsData);
-            Debug.Assert(_sWindowsName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sWindowsName to be populated by already");
+            Debug.Assert(_sRealName != null, "[CultureData.DoGetLocaleInfoInt] Expected _sRealName to be populated by already");
 
-            int result = GetLocaleInfoExInt(_sWindowsName, Interop.Kernel32.LOCALE_IFIRSTDAYOFWEEK | (!_bUseOverrides ? Interop.Kernel32.LOCALE_NOUSEROVERRIDE : 0));
+            int result = GetLocaleInfoExInt(_sRealName, Interop.Kernel32.LOCALE_IFIRSTDAYOFWEEK | (!_bUseOverrides ? Interop.Kernel32.LOCALE_NOUSEROVERRIDE : 0));
 
             // Win32 and .NET disagree on the numbering for days of the week, so we have to convert.
             return ConvertFirstDayOfWeekMonToSun(result);
@@ -529,7 +529,7 @@ namespace System.Globalization
 
                 for (int i = 0; i < context.strings.Count; i++)
                 {
-                    if (string.Equals(context.strings[i], _sWindowsName, StringComparison.OrdinalIgnoreCase))
+                    if (string.Equals(context.strings[i], _sRealName, StringComparison.OrdinalIgnoreCase))
                         return true;
                 }