From f51e845cfaa07776cbeb4468656e5ea89342ee9f Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Tue, 28 Jul 2020 16:37:23 -0700 Subject: [PATCH] Fix creating RegionInfo object using names with different casing. --- .../System/Globalization/RegionInfoTests.cs | 18 ++++++++++++++++++ .../src/System/Globalization/CultureData.cs | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs index 2cb86dc56da24..84cc05e356276 100644 --- a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs +++ b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs @@ -79,6 +79,24 @@ public void CurrentRegion_Windows() }).Dispose(); } + + [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + // We are testing with "no" as it match a neutral culture name. We want ensure this not conflict with region name. + [InlineData("no")] + [InlineData("No")] + [InlineData("NO")] + public void ValidateUsingCasedRegionName(string regionName) + { + RemoteExecutor.Invoke(name => + { + // It is important to do this test in the following order because we have internal cache for regions. + // creating the region with the original input name should be the first to do to ensure not cached before. + string resultedName = new RegionInfo(name).Name; + string expectedName = new RegionInfo(name.ToUpperInvariant()).Name; + Assert.Equal(expectedName, resultedName); + }, regionName).Dispose(); + } + [Theory] [InlineData("en-US", "United States")] [OuterLoop("May fail on machines with multiple language packs installed")] // see https://github.com/dotnet/runtime/issues/30132 diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs index 6c0dbe1687978..939c16e4d8d9a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -152,7 +152,7 @@ internal partial class CultureData /// private static Dictionary RegionNames => s_regionNames ??= - new Dictionary(257 /* prime */) + new Dictionary(257 /* prime */, StringComparer.OrdinalIgnoreCase) { { "001", "en-001" }, { "029", "en-029" },