From 46cf185d4f411040d3669734d77f7322abd883c9 Mon Sep 17 00:00:00 2001 From: x0b Date: Sat, 30 Jun 2018 17:16:45 +0200 Subject: [PATCH] fix off-by-one-error --- .../main/java/io/github/x0b/rfc3339parser/Rfc3339.java | 2 +- .../java/io/github/x0b/rfc3339parser/Rfc3339Test.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/rfc3339parser/src/main/java/io/github/x0b/rfc3339parser/Rfc3339.java b/rfc3339parser/src/main/java/io/github/x0b/rfc3339parser/Rfc3339.java index 8e04c1e..aa19eda 100644 --- a/rfc3339parser/src/main/java/io/github/x0b/rfc3339parser/Rfc3339.java +++ b/rfc3339parser/src/main/java/io/github/x0b/rfc3339parser/Rfc3339.java @@ -178,7 +178,7 @@ private synchronized static Date parseOffset(Date date, String timeString) throw private static char getTimezoneStyle(String timeString, char... styleIds){ for (char c: styleIds) { int lastIndex = timeString.lastIndexOf(c); - if(lastIndex != -1 && lastIndex > 19){ + if(lastIndex != -1 && lastIndex >= 19){ return c; } } diff --git a/rfc3339parser/src/test/java/io/github/x0b/rfc3339parser/Rfc3339Test.java b/rfc3339parser/src/test/java/io/github/x0b/rfc3339parser/Rfc3339Test.java index 89ded2b..9644ac3 100644 --- a/rfc3339parser/src/test/java/io/github/x0b/rfc3339parser/Rfc3339Test.java +++ b/rfc3339parser/src/test/java/io/github/x0b/rfc3339parser/Rfc3339Test.java @@ -4,6 +4,8 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.text.ParseException; import java.util.Calendar; @@ -143,6 +145,13 @@ public void parseTimeZoneUnsupportedFail() throws ParseException { Rfc3339.parseTimezone("1996-12-19T16:39:57.203GMT0800"); } + @Test + public void testInternalTzStyle() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Method getTzStyle = Rfc3339.class.getDeclaredMethod("getTimezoneStyle", String.class, char[].class); + getTzStyle.setAccessible(true); + getTzStyle.invoke(null, "1996-12-19T16:39:57+01:30", new char[]{'+', '-', 'Z'}); + } + @Test public void parseCalendar() throws ParseException { String timeString = "1996-12-19T16:39:57.123+01:30";