mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-06 22:15:31 +00:00
ICU-22568 return TimeZomeFormat::createInstance for bogus locale
This commit is contained in:
parent
83327fb92c
commit
d93c7b60fc
3 changed files with 17 additions and 4 deletions
|
@ -327,17 +327,18 @@ TimeZoneFormat::TimeZoneFormat(const Locale& locale, UErrorCode& status)
|
|||
const char* region = fLocale.getCountry();
|
||||
int32_t regionLen = static_cast<int32_t>(uprv_strlen(region));
|
||||
if (regionLen == 0) {
|
||||
UErrorCode tempStatus = U_ZERO_ERROR;
|
||||
CharString loc;
|
||||
{
|
||||
CharStringByteSink sink(&loc);
|
||||
ulocimp_addLikelySubtags(fLocale.getName(), sink, &status);
|
||||
ulocimp_addLikelySubtags(fLocale.getName(), sink, &tempStatus);
|
||||
}
|
||||
|
||||
regionLen = uloc_getCountry(loc.data(), fTargetRegion, sizeof(fTargetRegion), &status);
|
||||
if (U_SUCCESS(status)) {
|
||||
regionLen = uloc_getCountry(loc.data(), fTargetRegion, sizeof(fTargetRegion), &tempStatus);
|
||||
if (U_SUCCESS(tempStatus)) {
|
||||
fTargetRegion[regionLen] = 0;
|
||||
} else {
|
||||
return;
|
||||
fTargetRegion[0] = 0;
|
||||
}
|
||||
} else if (regionLen < (int32_t)sizeof(fTargetRegion)) {
|
||||
uprv_strcpy(fTargetRegion, region);
|
||||
|
|
|
@ -87,6 +87,7 @@ TimeZoneFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &name
|
|||
TESTCASE(7, TestFormatTZDBNamesAllZoneCoverage);
|
||||
TESTCASE(8, TestAdoptDefaultThreadSafe);
|
||||
TESTCASE(9, TestCentralTime);
|
||||
TESTCASE(10, TestBogusLocale);
|
||||
default: name = ""; break;
|
||||
}
|
||||
}
|
||||
|
@ -1402,4 +1403,14 @@ TimeZoneFormatTest::TestCentralTime() {
|
|||
}
|
||||
}
|
||||
}
|
||||
void
|
||||
TimeZoneFormatTest::TestBogusLocale() {
|
||||
Locale bogus("not a lang");
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
std::unique_ptr<icu::TimeZoneFormat> tzfmt(
|
||||
icu::TimeZoneFormat::createInstance(bogus, status));
|
||||
if (U_FAILURE(status)) {
|
||||
errln(u"Failed to createInstance with bogus locale");
|
||||
}
|
||||
}
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
|
|
@ -31,6 +31,7 @@ class TimeZoneFormatTest : public IntlTest {
|
|||
void TestFormatTZDBNamesAllZoneCoverage();
|
||||
void TestAdoptDefaultThreadSafe();
|
||||
void TestCentralTime();
|
||||
void TestBogusLocale();
|
||||
|
||||
void RunTimeRoundTripTests(int32_t threadNumber);
|
||||
void RunAdoptDefaultThreadSafeTests(int32_t threadNumber);
|
||||
|
|
Loading…
Add table
Reference in a new issue