From 1dcb4bcb2d78f8f7e8a3ce4889a36f7e965a7f7b Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Tue, 15 Oct 2024 10:20:39 -0700 Subject: [PATCH] ICU-22765 fix uloc_addLikelySubtags on "und@x=private" --- icu4c/source/common/loclikelysubtags.cpp | 2 +- icu4c/source/test/cintltst/cloctst.c | 7 +++++++ icu4c/source/test/intltest/loctest.cpp | 9 +++++++++ .../java/com/ibm/icu/dev/test/util/ULocaleTest.java | 10 +++++++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/icu4c/source/common/loclikelysubtags.cpp b/icu4c/source/common/loclikelysubtags.cpp index 7c6131197d89..7245a779816c 100644 --- a/icu4c/source/common/loclikelysubtags.cpp +++ b/icu4c/source/common/loclikelysubtags.cpp @@ -527,7 +527,7 @@ LSR LikelySubtags::makeMaximizedLsrFrom(const Locale &locale, return {}; } const char *name = locale.getName(); - if (uprv_isAtSign(name[0]) && name[1] == 'x' && name[2] == '=') { // name.startsWith("@x=") + if (!returnInputIfUnmatch && uprv_isAtSign(name[0]) && name[1] == 'x' && name[2] == '=') { // name.startsWith("@x=") // Private use language tag x-subtag-subtag... which CLDR changes to // und-x-subtag-subtag... return LSR(name, "", "", LSR::EXPLICIT_LSR); diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c index 1a6c20fdcd2a..8dbf04572daf 100644 --- a/icu4c/source/test/cintltst/cloctst.c +++ b/icu4c/source/test/cintltst/cloctst.c @@ -3924,6 +3924,13 @@ const char* const basic_maximize_data[][2] = { // ICU-22545 & ICU-22742 "ru_XC", "ru_Cyrl_XC" + }, { + // ICU-22765 + "und@x=private", + "en_Latn_US@x=private", + }, { + "th@x=private", + "th_Thai_TH@x=private", } }; diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index d62e2548a249..14244efa704c 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -4124,6 +4124,15 @@ LocaleTest::TestAddLikelyAndMinimizeSubtags() { "en_PSCRACK", "en_Latn_US_PSCRACK", "en__PSCRACK" + }, { + // ICU-22765 + "th@x=private", + "th_Thai_TH@x=private", + "th@x=private", + }, { + "und@x=private", + "en_Latn_US@x=private", + "en@x=private", } }; diff --git a/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/util/ULocaleTest.java b/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/util/ULocaleTest.java index 02146417fc33..e862efccf3a0 100644 --- a/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/util/ULocaleTest.java +++ b/icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/util/ULocaleTest.java @@ -4162,7 +4162,15 @@ else if (!res.toString().equals(exp)) { "und_US", "en_Latn_US", "en" - } + }, { + "th@x=private", + "th_Thai_TH@x=private", + "th@x=private", + }, { + "und@x=private", + "en_Latn_US@x=private", + "en@x=private", + } }; for (int i = 0; i < full_data.length; i++) {