From 65a6458eaa2e1f88278e4bb5753a68bd825e3a80 Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Thu, 27 Sep 2012 00:55:31 +0000 Subject: [PATCH] LANG-832 FastDateParser does not handle unterminated quotes correctly git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1390795 13f79535-47bb-0310-9956-ffa450edef68 --- src/changes/changes.xml | 1 + .../java/org/apache/commons/lang3/time/FastDateParser.java | 3 +++ .../org/apache/commons/lang3/time/FastDateParserTest.java | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b0244500c..39e83430e 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ + FastDateParser does not handle unterminated quotes correctly FastDateParser does not handle white-space properly FastDateParser does not handle non-Gregorian calendars properly FastDateParser does not handle non-ASCII digits correctly diff --git a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java index 8df302f9c..38857c74b 100644 --- a/src/main/java/org/apache/commons/lang3/time/FastDateParser.java +++ b/src/main/java/org/apache/commons/lang3/time/FastDateParser.java @@ -141,6 +141,9 @@ public class FastDateParser implements DateParser, Serializable { currentFormatField= nextFormatField; currentStrategy= nextStrategy; } + if (patternMatcher.regionStart() != patternMatcher.regionEnd()) { + throw new IllegalArgumentException("Failed to parse \""+pattern+"\" ; gave up at index "+patternMatcher.regionStart()); + } if(currentStrategy.addRegex(this, regex)) { collector.add(currentStrategy); } diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java index ee5a5008b..e2f12c101 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java @@ -333,6 +333,11 @@ public class FastDateParserTest { assertEquals(cal.getTime(), fdf.parse("'20030210A'B153320989'")); } + @Test + public void testLANG_832() throws Exception { + testSdfAndFdp("'d'd" ,"d3", false); // OK + testSdfAndFdp("'d'd'","d3", true); // should fail (unterminated quote) + } @Test public void testLANG_831() throws Exception {