This is an automated email from the ASF dual-hosted git repository. mohandv pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/metron.git
The following commit(s) were added to refs/heads/master by this push: new f36bba7 Metron-2180 IS_DATE stellar function is lenient while parsing date/time (MohanDV) closes apache/metron#1461 f36bba7 is described below commit f36bba7c0ed6a2cff3f30de73d7e2650e03681a6 Author: MohanDV <mohan...@gmail.com> AuthorDate: Fri Jul 12 16:53:20 2019 +0530 Metron-2180 IS_DATE stellar function is lenient while parsing date/time (MohanDV) closes apache/metron#1461 --- .../metron/common/field/validation/primitive/DateValidation.java | 3 +++ .../metron/common/field/validation/primitive/DateValidationTest.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/DateValidation.java b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/DateValidation.java index bc558e5..74d5464 100644 --- a/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/DateValidation.java +++ b/metron-platform/metron-common/src/main/java/org/apache/metron/common/field/validation/primitive/DateValidation.java @@ -67,6 +67,7 @@ public class DateValidation implements FieldValidation, Predicate<List<Object>> } try { SimpleDateFormat sdf = new SimpleDateFormat(format.toString()); + sdf.setLenient(false); sdf.parse(date.toString()); return true; } @@ -106,6 +107,7 @@ public class DateValidation implements FieldValidation, Predicate<List<Object>> return false; } SimpleDateFormat sdf = new SimpleDateFormat(format); + sdf.setLenient(false); for(Object o : input.values()) { if(o == null) { return true; @@ -126,6 +128,7 @@ public class DateValidation implements FieldValidation, Predicate<List<Object>> throw new IllegalStateException("You must specify '" + Config.FORMAT.key + "' in the config"); } SimpleDateFormat sdf = new SimpleDateFormat(format); + sdf.setLenient(false); try { sdf.format(new Date()); } diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/field/validation/primitive/DateValidationTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/field/validation/primitive/DateValidationTest.java index c39ea7b..c2339a3 100644 --- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/field/validation/primitive/DateValidationTest.java +++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/field/validation/primitive/DateValidationTest.java @@ -75,6 +75,10 @@ public class DateValidationTest extends BaseValidationTest{ Assert.assertFalse(execute(validWithSingleField, ImmutableMap.of("field1", "2014/05/01"))); Assert.assertFalse(runPredicate(validWithSingleField_MQL, ImmutableMap.of("field1", "2014/05/01"))); Assert.assertFalse(execute(validWithSingleField, ImmutableMap.of("field1", 2.3f))); + //invalid month + Assert.assertFalse(runPredicate(validWithSingleField_MQL, ImmutableMap.of("field1", "2014-25-01"))); + //invalid date + Assert.assertFalse(runPredicate(validWithSingleField_MQL, ImmutableMap.of("field1", "2014-05-32"))); } @Test public void positiveTest_multiple() throws IOException {