diff --git a/icu4c/source/common/uresdata.cpp b/icu4c/source/common/uresdata.cpp index b3c2e2e27c..ae731e4544 100644 --- a/icu4c/source/common/uresdata.cpp +++ b/icu4c/source/common/uresdata.cpp @@ -963,7 +963,7 @@ res_findResource(const ResourceData *pResData, Resource r, char** path, const ch if(t2 == RES_BOGUS) { /* if we fail to get the resource by key, maybe we got an index */ indexR = uprv_strtol(pathP, &closeIndex, 10); - if(indexR >= 0 && *closeIndex == 0) { + if(indexR >= 0 && *closeIndex == 0 && (*pathP != '0' || closeIndex - pathP == 1)) { /* if we indeed have an index, try to get the item by index */ t2 = res_getTableItemByIndex(pResData, t1, indexR, key); } // else t2 is already RES_BOGUS diff --git a/icu4c/source/test/intltest/locnmtst.cpp b/icu4c/source/test/intltest/locnmtst.cpp index 8e86f2f837..61baca2e46 100644 --- a/icu4c/source/test/intltest/locnmtst.cpp +++ b/icu4c/source/test/intltest/locnmtst.cpp @@ -82,6 +82,7 @@ void LocaleDisplayNamesTest::runIndexedTest(int32_t index, UBool exec, const cha TESTCASE(12, TestUldnDisplayContext); TESTCASE(13, TestUldnWithGarbage); TESTCASE(14, TestSubstituteHandling); + TESTCASE(15, TestNumericRegionID); #endif default: name = ""; @@ -420,6 +421,23 @@ void LocaleDisplayNamesTest::TestRootEtc() { delete ldn; } +void LocaleDisplayNamesTest::TestNumericRegionID() { + UErrorCode err = U_ZERO_ERROR; + ULocaleDisplayNames* ldn = uldn_open("es_MX", ULDN_STANDARD_NAMES, &err); + UChar displayName[200]; + int32_t displayNameLength = uldn_regionDisplayName(ldn, "019", displayName, 200, &err); + test_assert(U_SUCCESS(err)); + test_assert_equal(UnicodeString(u"América"), UnicodeString(displayName)); + uldn_close(ldn); + + err = U_ZERO_ERROR; // reset in case the test above returned an error code + ldn = uldn_open("en_AU", ULDN_STANDARD_NAMES, &err); + displayNameLength = uldn_regionDisplayName(ldn, "002", displayName, 200, &err); + test_assert(U_SUCCESS(err)); + test_assert_equal(UnicodeString(u"Africa"), UnicodeString(displayName)); + uldn_close(ldn); +} + static const char unknown_region[] = "wx"; static const char unknown_lang[] = "xy"; static const char unknown_script[] = "wxyz"; diff --git a/icu4c/source/test/intltest/locnmtst.h b/icu4c/source/test/intltest/locnmtst.h index ad0af463a1..e09a7d392c 100644 --- a/icu4c/source/test/intltest/locnmtst.h +++ b/icu4c/source/test/intltest/locnmtst.h @@ -38,6 +38,7 @@ public: void TestUldnDisplayContext(void); void TestUldnWithGarbage(void); void TestSubstituteHandling(void); + void TestNumericRegionID(void); void VerifySubstitute(LocaleDisplayNames* ldn); void VerifyNoSubstitute(LocaleDisplayNames* ldn);