Skip to content

Commit

Permalink
Account for PredefinedCulturesOnly in CultureInfo LCID .ctor (#87002)
Browse files Browse the repository at this point in the history
  • Loading branch information
OwnageIsMagic authored Jun 2, 2023
1 parent 0c85307 commit f4ef5c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,16 @@ public void TestGetCultureInfo_PredefinedOnly_ReturnsSame()
Assert.Equal(CultureInfo.GetCultureInfo("en-US"), CultureInfo.GetCultureInfo("en-US", predefinedOnly: true));
}

[ConditionalTheory(nameof(PredefinedCulturesOnlyIsDisabled))]
[InlineData(0x0001)]
[InlineData(0x7c5C)]
[InlineData(0x03_0404)] // with sort id
[InlineData(0x007F)] // LOCALE_INVARIANT
public void TestCultureInfo_Ctor_Int32_ReturnsInvariant(int culture)
{
Assert.Equal(new CultureInfo(culture), CultureInfo.InvariantCulture);
}

private static byte[] GetExpectedInvariantOrdinalSortKey(ReadOnlySpan<char> input)
{
MemoryStream memoryStream = new MemoryStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,16 @@ internal static CultureData GetCultureData(int culture, bool bUseUserOverride)

if (GlobalizationMode.Invariant)
{
if (!GlobalizationMode.PredefinedCulturesOnly)
{
if (culture is < 1 or > 0xf_ffff)
{
throw new CultureNotFoundException(nameof(culture), culture, SR.Argument_CultureNotSupported);
}

return Invariant;
}

// LCID is not supported in the InvariantMode
throw new CultureNotFoundException(nameof(culture), culture, SR.Argument_CultureNotSupportedInInvariantMode);
}
Expand Down

0 comments on commit f4ef5c8

Please sign in to comment.