LANG-1380: FastDateParser too strict on abbreviated short month symbols

This commit is contained in:
Chas Honton 2018-07-02 20:39:24 -07:00
parent ae6a24dd43
commit f56931c176
3 changed files with 30 additions and 4 deletions

View File

@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="3.8" date="2018-MM-DD" description="New features and bug fixes. Requires Java 7, supports Java 8, 9, 10.">
<action issue="LANG-1380" type="fix" dev="chas" due-to="Markus Jelsma">FastDateParser too strict on abbreviated short month symbols</action>
<action issue="LANG-1396" type="fix" dev="sebb">JsonToStringStyle does not escape string names</action>
<action issue="LANG-1395" type="fix" dev="sebb" due-to="Jim Gan">JsonToStringStyle does not escape double quote in a string value</action>
<action issue="LANG-1384" type="fix" dev="erans" due-to="Ian Young">New Java version ("11") must be handled</action>

View File

@ -448,6 +448,10 @@ private static StringBuilder simpleQuote(final StringBuilder sb, final String va
sb.append(c);
}
}
if(sb.charAt(sb.length() - 1) == '.') {
// trailing '.' is optional
sb.append('?');
}
return sb;
}
@ -713,7 +717,12 @@ private static class CaseInsensitiveTextStrategy extends PatternStrategy {
*/
@Override
void setCalendar(final FastDateParser parser, final Calendar cal, final String value) {
final Integer iVal = lKeyValues.get(value.toLowerCase(locale));
final String lowerCase = value.toLowerCase(locale);
Integer iVal = lKeyValues.get(lowerCase);
if(iVal == null) {
// match missing the optional trailing period
iVal = lKeyValues.get(lowerCase + '.');
}
cal.set(field, iVal.intValue());
}
}
@ -892,7 +901,12 @@ void setCalendar(final FastDateParser parser, final Calendar cal, final String t
if (tz != null) {
cal.setTimeZone(tz);
} else {
final TzInfo tzInfo = tzNames.get(timeZone.toLowerCase(locale));
final String lowerCase = timeZone.toLowerCase(locale);
TzInfo tzInfo = tzNames.get(lowerCase);
if (tzInfo == null) {
// match missing the optional trailing period
tzInfo = tzNames.get(lowerCase + '.');
}
cal.set(Calendar.DST_OFFSET, tzInfo.dstOffset);
cal.set(Calendar.ZONE_OFFSET, tzInfo.zone.getRawOffset());
}

View File

@ -32,7 +32,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import org.apache.commons.lang3.LocaleUtils;
import org.apache.commons.lang3.SerializationUtils;
import org.junit.Test;
@ -717,4 +716,16 @@ public void testDayNumberOfWeek() throws ParseException {
calendar.setTime(parser.parse("7"));
assertEquals(Calendar.SUNDAY, calendar.get(Calendar.DAY_OF_WEEK));
}
@Test
public void testLang1380() throws ParseException {
final Calendar expected = Calendar.getInstance(GMT, Locale.FRANCE);
expected.clear();
expected.set(2014, Calendar.APRIL, 14);
final DateParser fdp = getInstance("dd MMM yyyy", GMT, Locale.FRANCE);
assertEquals(expected.getTime(), fdp.parse("14 avril 2014"));
assertEquals(expected.getTime(), fdp.parse("14 avr. 2014"));
assertEquals(expected.getTime(), fdp.parse("14 avr 2014"));
}
}