From 9ab5487eb8eae94dcacb810c6ed3318f7f3c1262 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Wed, 21 Oct 2020 14:11:40 -0700 Subject: [PATCH] ICU-21344 Fix wrong passing of script in Locale. Also add same unit test in Java which have no problem. --- icu4c/source/common/locid.cpp | 6 +++++- icu4c/source/test/intltest/loctest.cpp | 3 +++ .../core/src/com/ibm/icu/dev/test/util/ULocaleTest.java | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/icu4c/source/common/locid.cpp b/icu4c/source/common/locid.cpp index 2804e36bf62..cc25414b09c 100644 --- a/icu4c/source/common/locid.cpp +++ b/icu4c/source/common/locid.cpp @@ -35,6 +35,7 @@ #include "unicode/bytestream.h" #include "unicode/locid.h" +#include "unicode/localebuilder.h" #include "unicode/strenum.h" #include "unicode/stringpiece.h" #include "unicode/uloc.h" @@ -1336,7 +1337,10 @@ AliasReplacer::replaceTerritory(UVector& toBeFreed, UErrorCode& status) // Cannot use nullptr for language because that will construct // the default locale, in that case, use "und" to get the correct // locale. - Locale l(language == nullptr ? "und" : language, nullptr, script); + Locale l = LocaleBuilder() + .setLanguage(language == nullptr ? "und" : language) + .setScript(script) + .build(status); l.addLikelySubtags(status); const char* likelyRegion = l.getCountry(); CharString* item = nullptr; diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index b80711951a2..a847a957d98 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -4894,6 +4894,9 @@ void LocaleTest::TestCanonicalize(void) { "ja-Latn-hepburn-heploc", "ja-Latn-alalc97"}, { "aaa-Fooo-SU", "aaa-Fooo-RU"}, + + // ICU-21344 + { "ku-Arab-NT", "ku-Arab-IQ"}, }; int32_t i; for (i=0; i < UPRV_LENGTHOF(testCases); i++) { diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java index bfa04d6ff11..40bcb0e4b26 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ULocaleTest.java @@ -5212,6 +5212,9 @@ public class ULocaleTest extends TestFmwk { Assert.assertEquals("ja-Latn-alalc97", canonicalTag("ja-Latn-hepburn-heploc")); Assert.assertEquals("aaa-Fooo-RU", canonicalTag("aaa-Fooo-SU")); + + // ICU-21344 + Assert.assertEquals("ku-Arab-IQ", canonicalTag("ku-Arab-NT")); } @Test -- 2.40.0