File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
main/java/org/elasticsearch/xpack/sql/util
test/java/org/elasticsearch/xpack/sql/parser Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,8 @@ public static ZonedDateTime asDateTime(String dateFormat) {
111111
112112 public static ZonedDateTime ofEscapedLiteral (String dateFormat ) {
113113 int separatorIdx = dateFormat .lastIndexOf ('-' ) + 3 ;
114- if (dateFormat .charAt (separatorIdx ) == 'T' ) {
114+ // Avoid index out of bounds - it will lead to DateTimeParseException anyways
115+ if (separatorIdx >= dateFormat .length () || dateFormat .charAt (separatorIdx ) == 'T' ) {
115116 return ZonedDateTime .parse (dateFormat , DATE_TIME_ESCAPED_LITERAL_FORMATTER_T_LITERAL .withZone (UTC ));
116117 } else {
117118 return ZonedDateTime .parse (dateFormat , DATE_TIME_ESCAPED_LITERAL_FORMATTER_WHITESPACE .withZone (UTC ));
Original file line number Diff line number Diff line change @@ -250,14 +250,21 @@ public void testTimestampLiteral() {
250250 }
251251
252252 public void testTimestampLiteralValidation () {
253- ParsingException ex = expectThrows (ParsingException .class , () -> timestampLiteral ("2012-01-01_AB 10:01:02.3456" ));
253+ String date = buildDate ();
254+ ParsingException ex = expectThrows (ParsingException .class , () -> timestampLiteral (date + "_AB 10:01:02.3456" ));
254255 assertEquals (
255- "line 1:2: Invalid timestamp received; Text '2012-01-01_AB 10:01:02.3456' could not be parsed at index 10" ,
256+ "line 1:2: Invalid timestamp received; Text '" + date + "_AB 10:01:02.3456' could not be parsed at index " +
257+ date .length (),
256258 ex .getMessage ());
257259 ex = expectThrows (ParsingException .class , () -> timestampLiteral ("20120101_AB 10:01:02.3456" ));
258260 assertEquals (
259261 "line 1:2: Invalid timestamp received; Text '20120101_AB 10:01:02.3456' could not be parsed at index 0" ,
260262 ex .getMessage ());
263+
264+ ex = expectThrows (ParsingException .class , () -> timestampLiteral (date ));
265+ assertEquals (
266+ "line 1:2: Invalid timestamp received; Text '" + date + "' could not be parsed at index " + date .length (),
267+ ex .getMessage ());
261268 }
262269
263270 public void testGUID () {
You can’t perform that action at this time.
0 commit comments