[
https://issues.apache.org/jira/browse/CLI-193?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12880690#action_12880690
]
Emmanuel Bourg commented on CLI-193:
------------------------------------
The proposed change makes sense but it doesn't solve completely the issue with
"unbreakable" text.
For example, considering the following test:
{code}
public void testRenderWrappedTextWordCut()
{
int width = 7;
int padding = 0;
String text = "Thisisatest.";
String expected = "Thisisa" + EOL +
"test.";
StringBuffer sb = new StringBuffer();
new HelpFormatter().renderWrappedText(sb, width, padding, text);
System.out.println(sb.toString());
assertEquals("cut and wrap", expected, sb.toString());
}
{code}
With the current code it throws a StringIndexOutOfBoundsException. With the
modification it fails because the text is not cut.
> StringIndexOutOfBoundsException in HelpFormatter.findWrapPos
> ------------------------------------------------------------
>
> Key: CLI-193
> URL: https://issues.apache.org/jira/browse/CLI-193
> Project: Commons CLI
> Issue Type: Bug
> Components: CLI-1.x
> Affects Versions: 1.2
> Reporter: Travis McLeskey
> Priority: Critical
> Fix For: 1.3
>
> Attachments: cli-helpformatter-stringIndexOOB.patch
>
> Original Estimate: 0.08h
> Remaining Estimate: 0.08h
>
> In the last while loop in HelpFormatter.findWrapPos, it can pass
> text.length() to text.charAt(int), which throws a
> StringIndexOutOfBoundsException. The first expression in that while loop
> condition should use a <, not a <=.
> This is on line 908 in r779646:
>
> http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli/HelpFormatter.java?revision=779646&view=markup
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.