Skip to content
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 @@ -254,5 +254,18 @@ public void EqualsTest(RegionInfo regionInfo1, object obj, bool expected)
Assert.Equal(expected, regionInfo1.GetHashCode().Equals(obj.GetHashCode()));
}
}

[Fact]
public void ValidateThrowingWhenUsingCustomUnspecifiedLcid()
{
// When trying to create RegionInfo using Lcid, we call LcidToLocaleName to map the Lcid to the culture name.
// LOCALE_CUSTOM_UNSPECIFIED (0x1000) is considered invalid Lcid to create cultures with. Sometimes Windows can
// map which is wrong. This happen if we enumerate the cultures before trying to create the RegionInfo object.
// This test is to ensure we'll not allow this creation in .NET.

CultureInfo [] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);

AssertExtensions.Throws<ArgumentException>("culture", () => new RegionInfo(4096));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ internal static unsafe CultureData GetCurrentRegionData()
{
Debug.Assert(!GlobalizationMode.Invariant);

// LOCALE_CUSTOM_UNSPECIFIED ia an unspecified custom locale, used to identify all supplemental locales.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ia an"

// Supplemental locales cannot be distinguished from one another by their locale identifiers, but can be distinguished by their locale names.
if (culture == CultureInfo.LOCALE_CUSTOM_UNSPECIFIED)
{
return null;
}

char* pBuffer = stackalloc char[Interop.Kernel32.LOCALE_NAME_MAX_LENGTH + 1]; // +1 for the null termination
int length = Interop.Kernel32.LCIDToLocaleName(culture, pBuffer, Interop.Kernel32.LOCALE_NAME_MAX_LENGTH + 1, Interop.Kernel32.LOCALE_ALLOW_NEUTRAL_NAMES);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public RegionInfo(int culture)
throw new ArgumentException(SR.Format(SR.Argument_CultureIsNeutral, culture), nameof(culture));
}

if (culture == CultureInfo.LOCALE_CUSTOM_DEFAULT)
if (culture == CultureInfo.LOCALE_CUSTOM_DEFAULT || culture == CultureInfo.LOCALE_CUSTOM_UNSPECIFIED)
{
// Not supposed to be neutral
throw new ArgumentException(SR.Format(SR.Argument_CustomCultureCannotBePassedByNumber, culture), nameof(culture));
Expand Down