From 81d58ab6d00867bd204371fb63b47f7936e6b020 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Wed, 6 Jan 2021 02:29:56 +0200 Subject: [PATCH] Handle '/' in locale name in PAL (#46601) --- src/libraries/Native/Unix/System.Globalization.Native/pal_locale.c | 6 +++++- .../System.Globalization/tests/CultureInfo/GetCultureInfo.cs | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_locale.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_locale.c index a96d5d9..5024fb0 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_locale.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_locale.c @@ -46,7 +46,11 @@ int32_t GetLocale(const UChar* localeName, { UChar c = localeName[i]; - if (c > (UChar)0x7F) + // Some versions of ICU have a bug where '/' in name can cause infinite loop, so we preemptively + // detect this case for CultureNotFoundException (as '/' is anyway illegal in locale name and we + // expected ICU to return this error). + + if (c > (UChar)0x7F || c == (UChar)'/') { *err = U_ILLEGAL_ARGUMENT_ERROR; return ULOC_FULLNAME_CAPACITY; diff --git a/src/libraries/System.Globalization/tests/CultureInfo/GetCultureInfo.cs b/src/libraries/System.Globalization/tests/CultureInfo/GetCultureInfo.cs index c5a3d5c..8ddfe93 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/GetCultureInfo.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/GetCultureInfo.cs @@ -25,6 +25,7 @@ namespace System.Globalization.Tests [ConditionalTheory(nameof(PlatformSupportsFakeCulture))] [InlineData("en@US")] [InlineData("\uFFFF")] + [InlineData("/")] public void TestInvalidCultureNames(string name) { Assert.Throws(() => CultureInfo.GetCultureInfo(name)); -- 2.7.4