This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new c07d4ec7 [CLI-341] HelpFormatter infinite loop with 0 width input
c07d4ec7 is described below

commit c07d4ec78a3df261f94816193544a9fd68c0cd84
Author: Gary D. Gregory <[email protected]>
AuthorDate: Sat Jun 21 17:31:42 2025 -0400

    [CLI-341] HelpFormatter infinite loop with 0 width input
    
    Add tests for negative input
---
 .../java/org/apache/commons/cli/HelpFormatterTest.java  | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/test/java/org/apache/commons/cli/HelpFormatterTest.java 
b/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
index 0d011223..de8c288f 100644
--- a/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
+++ b/src/test/java/org/apache/commons/cli/HelpFormatterTest.java
@@ -40,6 +40,7 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.Arguments;
 import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * Test case for the HelpFormatter class.
@@ -154,19 +155,21 @@ class HelpFormatterTest {
         assertEquals("usage: app -f <argument>" + EOL, out.toString());
     }
 
-    @Test
-    public void testDeprecatedFindWrapPosZeroWidth() {
-        final int pos = new HelpFormatter().findWrapPos("Hello World", 0, 0);
-        assertEquals(0, pos);
+    @ParameterizedTest
+    @ValueSource(ints = { -100, -1, 0 })
+    public void testDeprecatedFindWrapPosZeroWidth(final int width) {
+        final int pos = new HelpFormatter().findWrapPos("Hello World", width, 
0);
+        assertEquals(width, pos);
     }
 
-    @Test
-    public void testDeprecatedPrintOptionsZeroWidth() {
+    @ParameterizedTest
+    @ValueSource(ints = { -100, -1, 0 })
+    public void testDeprecatedPrintOptionsZeroWidth(final int width) {
         final Options options = new Options();
         options.addOption("h", "help", false, "Show help");
         final StringWriter out = new StringWriter();
         final PrintWriter pw = new PrintWriter(out);
-        new HelpFormatter().printOptions(pw, 0, options, 1, 3);
+        new HelpFormatter().printOptions(pw, width, options, 1, 3);
         final String result = out.toString();
         assertNotNull(result);
     }

Reply via email to