Skip to content

Commit dcc169b

Browse files
committed
[CLI-351] Multiple trailing BREAK_CHAR_SET characters cause infinite
loop in HelpFormatter
1 parent beef673 commit dcc169b

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<body>
2525
<release version="1.10.1" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required.">
2626
<!-- FIX -->
27+
<action type="fix" issue="CLI-351" dev="ggregory" due-to="Damien Carbonne, Claude Warren, Gary Gregory">Multiple trailing BREAK_CHAR_SET characters cause infinite loop in HelpFormatter.</action>
2728
<!-- ADD -->
2829
<!-- UPDATE -->
2930
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 85 to 88 #393.</action>

src/test/java/org/apache/commons/cli/help/HelpFormatterTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,19 @@ void testPrintHelp() throws IOException {
147147
assertEquals(0, sb.length(), "Should not write to output");
148148
}
149149

150+
/**
151+
* Tests example from the mailing list that caused an infinite loop.
152+
*
153+
* @see <a href="https://issues.apache.org/jira/browse/CLI-351">[CLI-351] Multiple traililng BREAK_CHAR_SET characters cause infinite loop in
154+
* HelpFormatter</a>
155+
*/
156+
@Test
157+
void testPrintHelpHeader() throws IOException {
158+
HelpFormatter.builder().get().printHelp("CL syntax", "Header", Collections.emptyList(), "Footer", true);
159+
HelpFormatter.builder().get().printHelp("CL syntax", "Header\n\n", // This makes printHelp enter into an infinite loop
160+
Collections.emptyList(), "Footer", true);
161+
}
162+
150163
@Test
151164
void testPrintHelpXML() throws IOException {
152165
final StringBuilder sb = new StringBuilder();

0 commit comments

Comments
 (0)