Skip to content
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

Fix calling NLS with Cultures has alternative sort names #61992

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public static IEnumerable<object[]> ToLower_TestData()
}
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
Expand Down Expand Up @@ -478,5 +478,13 @@ public void ToStringTest(string name, string expected)
{
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)
{
AssemblyTrademarkAttribute.Equals(1252, CultureInfo.GetCultureInfo(cultureName).TextInfo.ANSICodePage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ internal static unsafe int GetLocaleInfoEx(string lpLocaleName, uint lcType, cha
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
Expand All @@ -74,15 +74,15 @@ private int NlsGetLocaleInfo(LocaleNumberData type)

// 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 by 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)
Expand All @@ -94,16 +94,16 @@ internal static bool NlsIsEnsurePredefinedLocaleName(string name)
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);
Expand Down Expand Up @@ -529,7 +529,7 @@ internal bool NlsIsReplacementCulture

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;
}

Expand Down