From d14c7c413cc750f7c058fbc40f073d5f8d96d00c Mon Sep 17 00:00:00 2001
From: Amanda <83655710+arp-0984@users.noreply.github.com>
Date: Thu, 9 May 2024 15:44:05 +0000
Subject: [PATCH] Adding changes from PR 763
---
src/main/java/emissary/util/FlexibleDateTimeParser.java | 5 +++--
src/test/java/emissary/util/FlexibleDateTimeParserTest.java | 5 +++--
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/main/java/emissary/util/FlexibleDateTimeParser.java b/src/main/java/emissary/util/FlexibleDateTimeParser.java
index 5cb6d6fbe1..73834a9023 100644
--- a/src/main/java/emissary/util/FlexibleDateTimeParser.java
+++ b/src/main/java/emissary/util/FlexibleDateTimeParser.java
@@ -57,7 +57,7 @@ public final class FlexibleDateTimeParser {
* Remove other junk -- anything in an html tag, all parenthesis and quotes, and any non-word characters at the
* beginning or end
*/
- private static final Pattern REMOVE = Pattern.compile("<.+?>|=0D$|\\(|\\)|\"|\\[|]|\\W+$|^\\W+", Pattern.DOTALL);
+ private static final Pattern REMOVE = Pattern.compile("<.+?>$|=0D$|\\(|\\)|\"|\\[|]|\\W+$|^\\W+", Pattern.DOTALL);
private static final Pattern PHT_REPLACE = Pattern.compile("PHT");
private static final String PT_TIMEZONE = "PT";
@@ -264,7 +264,8 @@ private static String cleanDateString(final String date) {
return date;
}
- String cleanedDateString = date;
+ // date strings over 100 characters are more than likely invalid
+ String cleanedDateString = StringUtils.substring(date, 0, 100);
cleanedDateString = REPLACE.matcher(cleanedDateString).replaceAll(SPACE);
cleanedDateString = REMOVE.matcher(cleanedDateString).replaceAll(EMPTY);
diff --git a/src/test/java/emissary/util/FlexibleDateTimeParserTest.java b/src/test/java/emissary/util/FlexibleDateTimeParserTest.java
index 3076550a46..0ea9923831 100644
--- a/src/test/java/emissary/util/FlexibleDateTimeParserTest.java
+++ b/src/test/java/emissary/util/FlexibleDateTimeParserTest.java
@@ -2,6 +2,7 @@
import emissary.test.core.junit5.UnitTest;
+import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -622,6 +623,7 @@ void parse_yyyy_DDD() {
@Test
void testCleanDateString() {
test("2016-01-04 18:20
", EXPECTED_NO_SECS, "HTML");
+ test("2016-01-04 18:20
br>", EXPECTED_NO_SECS, "HTML");
test("2016-01-04\t\t18:20", EXPECTED_NO_SECS, "TABS");
test("2016-01-04 18:20", EXPECTED_NO_SECS, "SPACES");
test("2016-01-04 18:20=0D", EXPECTED_NO_SECS, "qp'ified ending");
@@ -629,8 +631,6 @@ void testCleanDateString() {
test("2016-01-04 (18:20:00)", EXPECTED_NO_SECS, "Extra parenthesis");
test("2016-01-04 18:20:00 [GMT]", EXPECTED_NO_SECS, "Extra brackets");
test("\"Mon\", 4 Jan 2016 18:20 +0000 \"EST\"", EXPECTED_NO_SECS, "Extra quotes");
- test("2016-01-04 18:20:00 +0000.1234", EXPECTED_NO_SECS, "");
- test("2016-01-04 18:20:00", EXPECTED_NO_SECS, "");
}
@Test
@@ -641,5 +641,6 @@ void testBad() {
assertNull(FlexibleDateTimeParser.parse("1234", Collections.singletonList(null)));
test("17.Mar.2016", 0L, "UNKNOWN");
test("Mon, 2 Feb 2017 06:20:30 PM +0000", 0L, "UNKNOWN");
+ test("2016:01:04 18:20:30 GMT+0000<" + RandomStringUtils.randomAlphanumeric(75) + ">", 0L, "UNKNOWN");
}
}