ICU-21326 Changed res_findResource() so that it doesn't try index-based lookup in a table resource if the resource ID has a leading zero
This commit is contained in:
parent
d1dcb69318
commit
af7ed1f6d2
@ -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
|
||||
|
@ -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";
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user