]> granicus.if.org Git - icu/commitdiff
ICU-13744 Fixed an ICU4J date parsing regression issue causing IndexOutOfBoundsExcept...
authorYoshito Umaoka <y.umaoka@gmail.com>
Wed, 16 May 2018 18:59:22 +0000 (18:59 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Wed, 16 May 2018 18:59:22 +0000 (18:59 +0000)
X-SVN-Rev: 41383

icu4c/source/test/intltest/dtfmttst.cpp
icu4c/source/test/intltest/dtfmttst.h
icu4j/main/classes/core/src/com/ibm/icu/text/SimpleDateFormat.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateFormatTest.java

index 0674d7d954da3f50fb57be6b03eeff12fff592df..d6a34235aedda26f3175a3fe811d985c3b0c0e5c 100644 (file)
@@ -5539,6 +5539,15 @@ void DateFormatTest::TestDayPeriodParsing() {
         k150000, sdf.parse(UnicodeString("2015-11-13 03:00 noon"), errorCode));
 }
 
+void DateFormatTest::TestParseRegression13744() {
+    LocalPointer<DateFormat> dfmt(DateFormat::createDateTimeInstance(
+            DateFormat::SHORT, DateFormat::SHORT, Locale("en", "US")));
+    ParsePosition pos(0);
+    UnicodeString inDate("4/27/18");
+    dfmt->parse(inDate, pos);
+    assertEquals("Error index", inDate.length(), pos.getErrorIndex());
+}
+
 #endif /* #if !UCONFIG_NO_FORMATTING */
 
 //eof
index 711c6ac8330859c896b424510141d437c9bb1911..efc56732494d35616477712aec3eec1da1ef9591 100644 (file)
@@ -261,6 +261,7 @@ public:
     void TestDayPeriodWithLocales();
     void TestMinuteSecondFieldsInOddPlaces();
     void TestDayPeriodParsing();
+    void TestParseRegression13744();
 
 private:
     UBool showParse(DateFormat &format, const UnicodeString &formattedString);
index 8e52d77580ecfe364080df659b09fc825c83cced..02e18571db1fedcc2f28baed81a0bb81ef368642 100644 (file)
@@ -2845,7 +2845,7 @@ public class SimpleDateFormat extends DateFormat {
                     char afterType = ((PatternItem) after).type;
                     if (DATE_PATTERN_TYPE.contains(beforeType) != DATE_PATTERN_TYPE.contains(afterType)) {
                         int newPos = originalPos;
-                        while (true) {
+                        while (newPos < tlen) {
                             char ich = text.charAt(newPos);
                             if (!PatternProps.isWhiteSpace(ich)) {
                                 break;
index 205fe4e4cf9e6b4497317c1c4e0928666217601e..b82d1229584c11426582509523cacbfbfc806d06 100644 (file)
@@ -5422,4 +5422,13 @@ public class DateFormatTest extends TestFmwk {
         assertEquals("yyyy-MM-dd hh:mm b | 2015-11-13 03:00 midnight", k030000, sdf.parse("2015-11-13 03:00 midnight"));
         assertEquals("yyyy-MM-dd hh:mm b | 2015-11-13 03:00 noon", k150000, sdf.parse("2015-11-13 03:00 noon"));
     }
+
+    @Test
+    public void TestParseRegression13744() {
+        DateFormat dfmt = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US);
+        ParsePosition pos = new ParsePosition(0);
+        final String inDate = "4/27/18";    // date only, no time
+        dfmt.parse(inDate, pos);
+        assertEquals("Error index", inDate.length(), pos.getErrorIndex());
+    }
 }