This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-cli.git
commit a7da9615fa8895d083cccedc7a59cbc1a499ca37 Author: Gary Gregory <[email protected]> AuthorDate: Sat Aug 1 14:29:05 2026 -0400 Reject trailing text after the date in Converter.DATE (#435). Sort members --- src/changes/changes.xml | 1 + .../org/apache/commons/cli/ConverterTests.java | 40 +++++++++++----------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index dbccb62e..f952bc4c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -32,6 +32,7 @@ <action type="fix" dev="ggregory" due-to="Digiscrypt Technologies, Gary Gregory">Reject non-BMP code points in the Character type converter (#425).</action> <action type="fix" dev="ggregory" due-to="Digiscrypt Technologies, Gary Gregory">Reject invalid dates in Converter.DATE (#430).</action> <action type="fix" dev="ggregory" due-to="farkhalit rida, Gary Gregory">Reject an empty option name in getMatchingOptions (#434).</action> + <action type="fix" dev="ggregory" due-to="farkhalit rida, Gary Gregory">Reject trailing text after the date in Converter.DATE (#435).</action> <!-- ADD --> <!-- UPDATE --> <action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 91 to 103 #414, #416.</action> diff --git a/src/test/java/org/apache/commons/cli/ConverterTests.java b/src/test/java/org/apache/commons/cli/ConverterTests.java index 1f6690f7..57cb63f9 100644 --- a/src/test/java/org/apache/commons/cli/ConverterTests.java +++ b/src/test/java/org/apache/commons/cli/ConverterTests.java @@ -86,26 +86,6 @@ public class ConverterTests { assertThrows(java.text.ParseException.class, () -> Converter.DATE.apply("Jun 06 17:48:57 EDT 2002")); } - @Test - void testDateRejectsTrailingText() throws Exception { - final Date expected = new Date(1023400137000L); - final String formatted = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").format(expected); - assertEquals(expected, Converter.DATE.apply(formatted)); - assertThrows(java.text.ParseException.class, () -> Converter.DATE.apply(formatted + " trailing")); - } - - @Test - @DefaultLocale(language = "de", country = "DE") - void testDateRejectsTrailingTextLocaleDe() throws Exception { - // Trailing text must be rejected even when a non-English default locale parses the date, and - // the reported error position should point past the parsed date rather than at index 0. - final Date expected = new Date(1023400137000L); - final String formatted = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").format(expected); - assertEquals(expected, Converter.DATE.apply(formatted)); - final java.text.ParseException e = assertThrows(java.text.ParseException.class, () -> Converter.DATE.apply(formatted + " trailing")); - assertEquals(formatted.length(), e.getErrorOffset()); - } - @Test @DefaultLocale(language = "de", country = "DE") void testDateLocaleDe() throws Exception { @@ -132,6 +112,26 @@ public class ConverterTests { assertThrows(java.text.ParseException.class, () -> Converter.DATE.apply("Mon Jan 32 00:00:00 UTC 2024")); } + @Test + void testDateRejectsTrailingText() throws Exception { + final Date expected = new Date(1023400137000L); + final String formatted = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").format(expected); + assertEquals(expected, Converter.DATE.apply(formatted)); + assertThrows(java.text.ParseException.class, () -> Converter.DATE.apply(formatted + " trailing")); + } + + @Test + @DefaultLocale(language = "de", country = "DE") + void testDateRejectsTrailingTextLocaleDe() throws Exception { + // Trailing text must be rejected even when a non-English default locale parses the date, and + // the reported error position should point past the parsed date rather than at index 0. + final Date expected = new Date(1023400137000L); + final String formatted = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").format(expected); + assertEquals(expected, Converter.DATE.apply(formatted)); + final java.text.ParseException e = assertThrows(java.text.ParseException.class, () -> Converter.DATE.apply(formatted + " trailing")); + assertEquals(formatted.length(), e.getErrorOffset()); + } + @Test void testFile() throws Exception { final URL url = this.getClass().getClassLoader().getResource("./org/apache/commons/cli/existing-readable.file");
