Skip to content

Commit 8d8d972

Browse files
committed
PDFBOX-6119: catch exception, add some bad testcases
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930470 13f79535-47bb-0310-9956-ffa450edef68
1 parent d7ef0dd commit 8d8d972

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,14 @@ public static Calendar toCalendar(String date) throws IOException
9393

9494
if (Pattern.matches("^\\d{4}-\\d{2}-\\d{2}T.*", date))
9595
{
96-
return fromISO8601(date);
96+
try
97+
{
98+
return fromISO8601(date);
99+
}
100+
catch (DateTimeParseException ex)
101+
{
102+
throw new IOException(ex);
103+
}
97104
}
98105
if (date.startsWith("D:"))
99106
{

xmpbox/src/test/java/org/apache/xmpbox/DateConverterTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ void testDateConversion() throws IOException
109109
convDate = DateConverter.toCalendar("2025-09-03T15:43:47.989082+00:00");
110110
assertEquals(989, convDate.get(Calendar.MILLISECOND));
111111

112+
// test some bad strings
112113
assertThrows(IOException.class, () -> DateConverter.toCalendar("123"));
114+
assertThrows(IOException.class, () -> DateConverter.toCalendar("2008-12-31T19:48:30+19:00"));
115+
assertThrows(IOException.class, () -> DateConverter.toCalendar("2008-12-31T19:48:30-19:00"));
116+
assertThrows(IOException.class, () -> DateConverter.toCalendar("2008-12-02T21:04:0Z"));
117+
assertThrows(IOException.class, () -> DateConverter.toCalendar("0-01-01T00:00:00Z"));
118+
assertThrows(IOException.class, () -> DateConverter.toCalendar("2009-03-16T01:15:19-0-4:00"));
113119

114120
// Test missing seconds
115121
assertEquals(DateConverter.toCalendar("2015-12-08T12:07:00-05:00"),

0 commit comments

Comments
 (0)