From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Wed, 6 Jan 2021 00:29:56 +0000 (+0200) Subject: Handle '/' in locale name in PAL (#46601) X-Git-Tag: submit/tizen/20210909.063632~3930 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=81d58ab6d00867bd204371fb63b47f7936e6b020;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Handle '/' in locale name in PAL (#46601) --- 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));