mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-13215 DayPeriodRules.getInstance should ignore keywords to get correct data and not hang
X-SVN-Rev: 40196
This commit is contained in:
parent
acd53b0c18
commit
d515102c5a
4 changed files with 19 additions and 2 deletions
icu4c/source
icu4j/main
classes/core/src/com/ibm/icu/impl
tests/core/src/com/ibm/icu/dev/test/format
|
@ -340,7 +340,7 @@ const DayPeriodRules *DayPeriodRules::getInstance(const Locale &locale, UErrorCo
|
|||
// does), return NULL.
|
||||
if(U_FAILURE(errorCode)) { return NULL; }
|
||||
|
||||
const char *localeCode = locale.getName();
|
||||
const char *localeCode = locale.getBaseName();
|
||||
char name[ULOC_FULLNAME_CAPACITY];
|
||||
char parentName[ULOC_FULLNAME_CAPACITY];
|
||||
|
||||
|
|
|
@ -5251,6 +5251,15 @@ void DateFormatTest::TestDayPeriodWithLocales() {
|
|||
sdf.applyPattern(UnicodeString("hh:mm:ss BBBB"));
|
||||
assertEquals("hh:mm:ss BBBB | 01:00:00 | es", "01:00:00 de la madrugada",
|
||||
sdf.format(k010000, out.remove()));
|
||||
|
||||
// #13215: for locales with keywords, check hang in DayPeriodRules""getInstance(const Locale, ...),
|
||||
// which is called in SimpleDateFormat::format for patterns that include 'B'.
|
||||
sdf = SimpleDateFormat(UnicodeString(), Locale("en@calendar=buddhist"), errorCode);
|
||||
sdf.setTimeZone(*tz);
|
||||
|
||||
sdf.applyPattern(UnicodeString("hh:mm:ss BBBB"));
|
||||
assertEquals("hh:mm:ss BBBB | 01:00:00 | en@calendar=buddhist", "01:00:00 at night",
|
||||
sdf.format(k010000, out.remove()));
|
||||
}
|
||||
|
||||
void DateFormatTest::TestMinuteSecondFieldsInOddPlaces() {
|
||||
|
|
|
@ -242,7 +242,7 @@ public final class DayPeriodRules {
|
|||
* @return a DayPeriodRules object for `locale`.
|
||||
*/
|
||||
public static DayPeriodRules getInstance(ULocale locale) {
|
||||
String localeCode = locale.getName();
|
||||
String localeCode = locale.getBaseName();
|
||||
if (localeCode.isEmpty()) { localeCode = "root"; }
|
||||
|
||||
Integer ruleSetNum = null;
|
||||
|
|
|
@ -5195,6 +5195,14 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||
|
||||
sdf.applyPattern("hh:mm:ss BBBB");
|
||||
assertEquals("hh:mm:ss BBBB | 01:00:00 | es", "01:00:00 de la madrugada", sdf.format(k010000));
|
||||
|
||||
// #13215: for locales with keywords, check hang in DayPeriodRules.getInstance(ULocale),
|
||||
// which is called in SimpleDateFormat.format for patterns that include 'B'.
|
||||
sdf = new SimpleDateFormat("", new ULocale("en@calendar=buddhist"));
|
||||
sdf.setTimeZone(TimeZone.GMT_ZONE);
|
||||
|
||||
sdf.applyPattern("hh:mm:ss BBBB");
|
||||
assertEquals("hh:mm:ss BBBB | 01:00:00 | en@calendar=buddhist", "01:00:00 at night", sdf.format(k010000));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Reference in a new issue