Skip to content

Commit 9cb37e0

Browse files
author
Robert James Oxspring
committed
Line separator as first char for helpformatter footer and header no longer throws exception
BR: 21215 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@130113 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1314233 commit 9cb37e0

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/java/org/apache/commons/cli/HelpFormatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ protected int findWrapPos(String text, int width, int startPos)
797797
if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
798798
|| ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
799799
{
800-
return pos;
800+
return pos+1;
801801
}
802802
else if ((startPos + width) >= text.length())
803803
{
@@ -872,7 +872,7 @@ protected String rtrim(String s)
872872

873873
int pos = s.length();
874874

875-
while ((pos >= 0) && Character.isWhitespace(s.charAt(pos - 1)))
875+
while ((pos > 0) && Character.isWhitespace(s.charAt(pos - 1)))
876876
{
877877
--pos;
878878
}

src/test/org/apache/commons/cli/BugsTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,5 +497,22 @@ public void test31148() throws ParseException {
497497
assertTrue(cl.hasOption('o'));
498498
assertEquals("ovalue",cl.getOptionValue('o'));
499499
}
500+
501+
public void test21215() {
502+
Options options = new Options();
503+
HelpFormatter formatter = new HelpFormatter();
504+
String SEP = System.getProperty("line.separator");
505+
String header = SEP+"Header";
506+
String footer = "Footer";
507+
StringWriter out = new StringWriter();
508+
formatter.printHelp(new PrintWriter(out),80, "foobar", header, options, 2, 2, footer, true);
509+
assertEquals(
510+
"usage: foobar"+SEP+
511+
""+SEP+
512+
"Header"+SEP+
513+
""+SEP+
514+
"Footer"+SEP
515+
,out.toString());
516+
}
500517

501518
}

0 commit comments

Comments
 (0)