You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dan Armbrust (JIRA)" <ji...@apache.org> on 2008/02/18 23:22:34 UTC

[jira] Created: (CLI-151) HelpFormatter wraps incorrectly on every line beyond the first

HelpFormatter wraps incorrectly on every line beyond the first
--------------------------------------------------------------

                 Key: CLI-151
                 URL: https://issues.apache.org/jira/browse/CLI-151
             Project: Commons CLI
          Issue Type: Bug
          Components: CLI-1.x
            Reporter: Dan Armbrust


The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  

To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.

I don't have a patch (sorry) - but here is a corrected version of the method.

I fixed it in two places - both were using "width + startPos" when they should have been using width.

 protected int findWrapPos(String text, int width, int startPos)
    {
        int pos = -1;

        // the line ends before the max wrap pos or a new line char found
        if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
            || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
        {
            return pos+1;
        }
        else if ((width) >= text.length())
        {
            return -1;
        }


        // look for the last whitespace character before startPos+width
        pos = width;

        char c;

        while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
               && (c != '\n') && (c != '\r'))
        {
            --pos;
        }

        // if we found it - just return
        if (pos > startPos)
        {
            return pos;
        }
        
        // must look for the first whitespace chearacter after startPos 
        // + width
        pos = startPos + width;

        while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
               && (c != '\n') && (c != '\r'))
        {
            ++pos;
        }

        return (pos == text.length())        ? (-1) : pos;
    }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CLI-151) HelpFormatter wraps incorrectly on every line beyond the first

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated CLI-151:
------------------------------

    Fix Version/s: 1.2

> HelpFormatter wraps incorrectly on every line beyond the first
> --------------------------------------------------------------
>
>                 Key: CLI-151
>                 URL: https://issues.apache.org/jira/browse/CLI-151
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x
>            Reporter: Dan Armbrust
>             Fix For: 1.2
>
>
> The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  
> To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.
> I don't have a patch (sorry) - but here is a corrected version of the method.
> I fixed it in two places - both were using "width + startPos" when they should have been using width.
> {code}
>  protected int findWrapPos(String text, int width, int startPos)
>     {
>         int pos = -1;
>         // the line ends before the max wrap pos or a new line char found
>         if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
>             || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
>         {
>             return pos+1;
>         }
>         else if ((width) >= text.length())
>         {
>             return -1;
>         }
>         // look for the last whitespace character before startPos+width
>         pos = width;
>         char c;
>         while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             --pos;
>         }
>         // if we found it - just return
>         if (pos > startPos)
>         {
>             return pos;
>         }
>         
>         // must look for the first whitespace chearacter after startPos 
>         // + width
>         pos = startPos + width;
>         while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             ++pos;
>         }
>         return (pos == text.length())        ? (-1) : pos;
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CLI-151) HelpFormatter wraps incorrectly on every line beyond the first

Posted by "Dan Armbrust (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dan Armbrust updated CLI-151:
-----------------------------

    Description: 
The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  

To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.

I don't have a patch (sorry) - but here is a corrected version of the method.

I fixed it in two places - both were using "width + startPos" when they should have been using width.

{code}
 protected int findWrapPos(String text, int width, int startPos)
    {
        int pos = -1;

        // the line ends before the max wrap pos or a new line char found
        if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
            || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
        {
            return pos+1;
        }
        else if ((width) >= text.length())
        {
            return -1;
        }


        // look for the last whitespace character before startPos+width
        pos = width;

        char c;

        while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
               && (c != '\n') && (c != '\r'))
        {
            --pos;
        }

        // if we found it - just return
        if (pos > startPos)
        {
            return pos;
        }
        
        // must look for the first whitespace chearacter after startPos 
        // + width
        pos = startPos + width;

        while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
               && (c != '\n') && (c != '\r'))
        {
            ++pos;
        }

        return (pos == text.length())        ? (-1) : pos;
    }
{code}

  was:
The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  

To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.

I don't have a patch (sorry) - but here is a corrected version of the method.

I fixed it in two places - both were using "width + startPos" when they should have been using width.

 protected int findWrapPos(String text, int width, int startPos)
    {
        int pos = -1;

        // the line ends before the max wrap pos or a new line char found
        if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
            || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
        {
            return pos+1;
        }
        else if ((width) >= text.length())
        {
            return -1;
        }


        // look for the last whitespace character before startPos+width
        pos = width;

        char c;

        while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
               && (c != '\n') && (c != '\r'))
        {
            --pos;
        }

        // if we found it - just return
        if (pos > startPos)
        {
            return pos;
        }
        
        // must look for the first whitespace chearacter after startPos 
        // + width
        pos = startPos + width;

        while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
               && (c != '\n') && (c != '\r'))
        {
            ++pos;
        }

        return (pos == text.length())        ? (-1) : pos;
    }


> HelpFormatter wraps incorrectly on every line beyond the first
> --------------------------------------------------------------
>
>                 Key: CLI-151
>                 URL: https://issues.apache.org/jira/browse/CLI-151
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x
>            Reporter: Dan Armbrust
>
> The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  
> To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.
> I don't have a patch (sorry) - but here is a corrected version of the method.
> I fixed it in two places - both were using "width + startPos" when they should have been using width.
> {code}
>  protected int findWrapPos(String text, int width, int startPos)
>     {
>         int pos = -1;
>         // the line ends before the max wrap pos or a new line char found
>         if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
>             || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
>         {
>             return pos+1;
>         }
>         else if ((width) >= text.length())
>         {
>             return -1;
>         }
>         // look for the last whitespace character before startPos+width
>         pos = width;
>         char c;
>         while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             --pos;
>         }
>         // if we found it - just return
>         if (pos > startPos)
>         {
>             return pos;
>         }
>         
>         // must look for the first whitespace chearacter after startPos 
>         // + width
>         pos = startPos + width;
>         while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             ++pos;
>         }
>         return (pos == text.length())        ? (-1) : pos;
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (CLI-151) HelpFormatter wraps incorrectly on every line beyond the first

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed CLI-151.
-----------------------------

    Resolution: Fixed

I've sat and looked at the code fresh, and I agree with the 0 as a fix here. Digging into the new failing test, I think the errors are in other code - so closing this out again.

> HelpFormatter wraps incorrectly on every line beyond the first
> --------------------------------------------------------------
>
>                 Key: CLI-151
>                 URL: https://issues.apache.org/jira/browse/CLI-151
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>            Reporter: Dan Armbrust
>             Fix For: 1.2
>
>         Attachments: fix-wrapping.patch
>
>
> The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  
> To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.
> I don't have a patch (sorry) - but here is a corrected version of the method.
> I fixed it in two places - both were using "width + startPos" when they should have been using width.
> {code}
>  protected int findWrapPos(String text, int width, int startPos)
>     {
>         int pos = -1;
>         // the line ends before the max wrap pos or a new line char found
>         if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
>             || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
>         {
>             return pos+1;
>         }
>         else if ((width) >= text.length())
>         {
>             return -1;
>         }
>         // look for the last whitespace character before startPos+width
>         pos = width;
>         char c;
>         while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             --pos;
>         }
>         // if we found it - just return
>         if (pos > startPos)
>         {
>             return pos;
>         }
>         
>         // must look for the first whitespace chearacter after startPos 
>         // + width
>         pos = startPos + width;
>         while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             ++pos;
>         }
>         return (pos == text.length())        ? (-1) : pos;
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CLI-151) HelpFormatter wraps incorrectly on every line beyond the first

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg updated CLI-151:
-------------------------------

    Component/s:     (was: CLI-1.x)
                 Help formatter

> HelpFormatter wraps incorrectly on every line beyond the first
> --------------------------------------------------------------
>
>                 Key: CLI-151
>                 URL: https://issues.apache.org/jira/browse/CLI-151
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>            Reporter: Dan Armbrust
>             Fix For: 1.2
>
>         Attachments: fix-wrapping.patch
>
>
> The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  
> To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.
> I don't have a patch (sorry) - but here is a corrected version of the method.
> I fixed it in two places - both were using "width + startPos" when they should have been using width.
> {code}
>  protected int findWrapPos(String text, int width, int startPos)
>     {
>         int pos = -1;
>         // the line ends before the max wrap pos or a new line char found
>         if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
>             || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
>         {
>             return pos+1;
>         }
>         else if ((width) >= text.length())
>         {
>             return -1;
>         }
>         // look for the last whitespace character before startPos+width
>         pos = width;
>         char c;
>         while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             --pos;
>         }
>         // if we found it - just return
>         if (pos > startPos)
>         {
>             return pos;
>         }
>         
>         // must look for the first whitespace chearacter after startPos 
>         // + width
>         pos = startPos + width;
>         while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             ++pos;
>         }
>         return (pos == text.length())        ? (-1) : pos;
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CLI-151) HelpFormatter wraps incorrectly on every line beyond the first

Posted by "J. Lewis Muir (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-151?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12590028#action_12590028 ] 

J. Lewis Muir commented on CLI-151:
-----------------------------------

I have observed this same problem.

I'm not sure the suggested fix to {{findWrapPos}} is correct.  When I tried it, the {{testFindWrapPos}} test case failed with

{noformat}
[junit] wrap position 2 expected:<-1> but was:<16>
[junit] junit.framework.AssertionFailedError:
[junit]     wrap position 2 expected:<-1> but was:<16>
[junit]   at org.apache.commons.cli.HelpFormatterTest.testFindWrapPos(
[junit]     HelpFormatterTest.java:62)
{noformat}

I think the problem is actually in {{HelpFormatter.renderWrappedText}} ({{HelpFormatter.java}} line 812).  It calls {{findWrapPos}} with a start position of {{nextLineTabStop}}, but that's not right; it should be a start position of 0.

The line wrapping works for me after making this correction.  I will attach a patch containing this fix as well as an addition to the test cases to validate it.

> HelpFormatter wraps incorrectly on every line beyond the first
> --------------------------------------------------------------
>
>                 Key: CLI-151
>                 URL: https://issues.apache.org/jira/browse/CLI-151
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x
>            Reporter: Dan Armbrust
>             Fix For: 1.2
>
>
> The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  
> To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.
> I don't have a patch (sorry) - but here is a corrected version of the method.
> I fixed it in two places - both were using "width + startPos" when they should have been using width.
> {code}
>  protected int findWrapPos(String text, int width, int startPos)
>     {
>         int pos = -1;
>         // the line ends before the max wrap pos or a new line char found
>         if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
>             || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
>         {
>             return pos+1;
>         }
>         else if ((width) >= text.length())
>         {
>             return -1;
>         }
>         // look for the last whitespace character before startPos+width
>         pos = width;
>         char c;
>         while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             --pos;
>         }
>         // if we found it - just return
>         if (pos > startPos)
>         {
>             return pos;
>         }
>         
>         // must look for the first whitespace chearacter after startPos 
>         // + width
>         pos = startPos + width;
>         while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             ++pos;
>         }
>         return (pos == text.length())        ? (-1) : pos;
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CLI-151) HelpFormatter wraps incorrectly on every line beyond the first

Posted by "J. Lewis Muir (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

J. Lewis Muir updated CLI-151:
------------------------------

    Attachment: fix-wrapping.patch

Line wrapping fix.

> HelpFormatter wraps incorrectly on every line beyond the first
> --------------------------------------------------------------
>
>                 Key: CLI-151
>                 URL: https://issues.apache.org/jira/browse/CLI-151
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x
>            Reporter: Dan Armbrust
>             Fix For: 1.2
>
>         Attachments: fix-wrapping.patch
>
>
> The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  
> To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.
> I don't have a patch (sorry) - but here is a corrected version of the method.
> I fixed it in two places - both were using "width + startPos" when they should have been using width.
> {code}
>  protected int findWrapPos(String text, int width, int startPos)
>     {
>         int pos = -1;
>         // the line ends before the max wrap pos or a new line char found
>         if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
>             || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
>         {
>             return pos+1;
>         }
>         else if ((width) >= text.length())
>         {
>             return -1;
>         }
>         // look for the last whitespace character before startPos+width
>         pos = width;
>         char c;
>         while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             --pos;
>         }
>         // if we found it - just return
>         if (pos > startPos)
>         {
>             return pos;
>         }
>         
>         // must look for the first whitespace chearacter after startPos 
>         // + width
>         pos = startPos + width;
>         while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             ++pos;
>         }
>         return (pos == text.length())        ? (-1) : pos;
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (CLI-151) HelpFormatter wraps incorrectly on every line beyond the first

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell reopened CLI-151:
-------------------------------


This caused OutOfMemoryExceptions in some cases, so reopening.

> HelpFormatter wraps incorrectly on every line beyond the first
> --------------------------------------------------------------
>
>                 Key: CLI-151
>                 URL: https://issues.apache.org/jira/browse/CLI-151
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Help formatter
>            Reporter: Dan Armbrust
>             Fix For: 1.2
>
>         Attachments: fix-wrapping.patch
>
>
> The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  
> To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.
> I don't have a patch (sorry) - but here is a corrected version of the method.
> I fixed it in two places - both were using "width + startPos" when they should have been using width.
> {code}
>  protected int findWrapPos(String text, int width, int startPos)
>     {
>         int pos = -1;
>         // the line ends before the max wrap pos or a new line char found
>         if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
>             || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
>         {
>             return pos+1;
>         }
>         else if ((width) >= text.length())
>         {
>             return -1;
>         }
>         // look for the last whitespace character before startPos+width
>         pos = width;
>         char c;
>         while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             --pos;
>         }
>         // if we found it - just return
>         if (pos > startPos)
>         {
>             return pos;
>         }
>         
>         // must look for the first whitespace chearacter after startPos 
>         // + width
>         pos = startPos + width;
>         while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             ++pos;
>         }
>         return (pos == text.length())        ? (-1) : pos;
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (CLI-151) HelpFormatter wraps incorrectly on every line beyond the first

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed CLI-151.
-----------------------------

    Resolution: Fixed

Looks good to me - thanks for the report and the patch.

---

svn ci -m "Applying J. Lewis Muir's patch from CLI-151 fixing HelpFormatter so it wraps properly on multiple lines"

Sending        src/java/org/apache/commons/cli/HelpFormatter.java
Sending        src/test/org/apache/commons/cli/HelpFormatterTest.java
Transmitting file data ..
Committed revision 654428.

> HelpFormatter wraps incorrectly on every line beyond the first
> --------------------------------------------------------------
>
>                 Key: CLI-151
>                 URL: https://issues.apache.org/jira/browse/CLI-151
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x
>            Reporter: Dan Armbrust
>             Fix For: 1.2
>
>         Attachments: fix-wrapping.patch
>
>
> The method findWrapPos(...) in the HelpFormatter is a couple of bugs in the way that it deals with the "startPos" variable.  This causes it to format every line beyond the first line by "startPos" to many characters, beyond the specified width.  
> To see this, create an option with a long description, and then use the help formatter to print it.  The first line will be the correct length.  The 2nd, 3rd, etc lines will all be too long.
> I don't have a patch (sorry) - but here is a corrected version of the method.
> I fixed it in two places - both were using "width + startPos" when they should have been using width.
> {code}
>  protected int findWrapPos(String text, int width, int startPos)
>     {
>         int pos = -1;
>         // the line ends before the max wrap pos or a new line char found
>         if (((pos = text.indexOf('\n', startPos)) != -1 && pos <= width)
>             || ((pos = text.indexOf('\t', startPos)) != -1 && pos <= width))
>         {
>             return pos+1;
>         }
>         else if ((width) >= text.length())
>         {
>             return -1;
>         }
>         // look for the last whitespace character before startPos+width
>         pos = width;
>         char c;
>         while ((pos >= startPos) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             --pos;
>         }
>         // if we found it - just return
>         if (pos > startPos)
>         {
>             return pos;
>         }
>         
>         // must look for the first whitespace chearacter after startPos 
>         // + width
>         pos = startPos + width;
>         while ((pos <= text.length()) && ((c = text.charAt(pos)) != ' ')
>                && (c != '\n') && (c != '\r'))
>         {
>             ++pos;
>         }
>         return (pos == text.length())        ? (-1) : pos;
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.