diff --git a/icu4c/source/common/uloc_tag.cpp b/icu4c/source/common/uloc_tag.cpp index 035e09257df4..91d89fc1c992 100644 --- a/icu4c/source/common/uloc_tag.cpp +++ b/icu4c/source/common/uloc_tag.cpp @@ -670,9 +670,13 @@ _isTransformedExtensionSubtag(int32_t& state, const char* s, int32_t len) const int32_t kGotTKey = -1; // Got tkey, wait for tvalue. ERROR if stop here. const int32_t kGotTValue = 6; // Got tvalue, wait for tkey, tvalue or end + + if (len < 0) { + len = (int32_t)uprv_strlen(s); + } switch (state) { case kStart: - if (ultag_isLanguageSubtag(s, len)) { + if (ultag_isLanguageSubtag(s, len) && len != 4) { state = kGotLanguage; return TRUE; } diff --git a/icu4c/source/test/intltest/localebuildertest.cpp b/icu4c/source/test/intltest/localebuildertest.cpp index 13f6ecf41202..385f8d6739aa 100644 --- a/icu4c/source/test/intltest/localebuildertest.cpp +++ b/icu4c/source/test/intltest/localebuildertest.cpp @@ -1375,7 +1375,7 @@ void LocaleBuilderTest::TestSetExtensionValidateTIllFormed() { "9-", "-9", "-z", - // "Latn", // Per 2019-01-23 ICUTC, still accept 4alpha. See ICU-20321 + "Latn", "Latn-", "en-", "nob-", @@ -1400,6 +1400,8 @@ void LocaleBuilderTest::TestSetExtensionValidateTIllFormed() { "gab-Thai-TH-0bde-z9-abcde123-a1-", "gab-Thai-TH-0bde-z9-abcde123-a1-a", "gab-Thai-TH-0bde-z9-abcde123-a1-ab", + // ICU-21408 + "root", }; for (const char* ill : illFormed) { UErrorCode status = U_ZERO_ERROR;