Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update trailing character cleanup regex in FlexibleDateTimeParser #763

Merged
merged 5 commits into from May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/emissary/util/FlexibleDateTimeParser.java
Expand Up @@ -51,7 +51,7 @@
private static final Pattern REPLACE = Pattern.compile("\t+|[ ]+", Pattern.DOTALL);

/* Remove other junk */
private static final Pattern REMOVE = Pattern.compile("<.+?>|=0D$", Pattern.DOTALL);
private static final Pattern REMOVE = Pattern.compile("<.+?>$|=0D$", Pattern.DOTALL);

/* timezone - config var: TIMEZONE */
private static ZoneId timezone = ZoneId.of(DEFAULT_TIMEZONE);
Expand Down Expand Up @@ -225,9 +225,9 @@
return date;
}

String cleanedDateString = date;
// date strings over 100 characters are more than likely invalid
String cleanedDateString = REMOVE.matcher(StringUtils.substring(date, 0, 100)).replaceAll(EMPTY);
Fixed Show fixed Hide fixed
cleanedDateString = REPLACE.matcher(cleanedDateString).replaceAll(SPACE);
cleanedDateString = REMOVE.matcher(cleanedDateString).replaceAll(EMPTY);
return StringUtils.trimToNull(cleanedDateString);
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/java/emissary/util/FlexibleDateTimeParserTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -420,6 +421,7 @@ void parse_yyyy_DDD() {
@Test
void testCleanDateString() {
test("2016-01-04 18:20<br>", EXPECTED_NO_SECS, "HTML");
test("2016-01-04 18:20<br>br>", EXPECTED_NO_SECS, "HTML");
jpdahlke marked this conversation as resolved.
Show resolved Hide resolved
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");
Expand All @@ -433,5 +435,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");
}
}