Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-419

WordUtils.abbreviate bug when lower is greater than str.length

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: 2.5
    • Component/s: lang.*
    • Labels:
      None

      Description

      In WordUtils.abbreviate, upper is adjusted to the length of the string, then to lower.
      But lower is never adjusted to the length of the string, so if lower is greater than str.lengt(), upper will be too...
      Then, str.substring(0, upper) throw a StringIndexOutOfBoundsException

      The fix is to adjust lower to the length of the string

        Activity

        Hide
        v.behar Vincent Behar added a comment -

        here is a patch with the corresponding unit-test

        I also had to fix another assert statement in the unit test

        Show
        v.behar Vincent Behar added a comment - here is a patch with the corresponding unit-test I also had to fix another assert statement in the unit test
        Hide
        pbenedict pbenedict added a comment -

        Congrats on the logging the first 2.4 bug.

        Show
        pbenedict pbenedict added a comment - Congrats on the logging the first 2.4 bug.
        Hide
        bayard Henri Yandell added a comment -

        When I apply the patch, the tests don't pass. ie) Looks like the fix doesn't fix it.

        Show
        bayard Henri Yandell added a comment - When I apply the patch, the tests don't pass. ie) Looks like the fix doesn't fix it.
        Hide
        v.behar Vincent Behar added a comment -

        ok my mistake, I should have done something wrong yesterday while playing with it.
        I've done a clean checkout and fixed the patch : the new one (...fixed.patch) is good, I checked it with "mvn test".

        Show
        v.behar Vincent Behar added a comment - ok my mistake, I should have done something wrong yesterday while playing with it. I've done a clean checkout and fixed the patch : the new one (...fixed.patch) is good, I checked it with "mvn test".
        Hide
        bayard Henri Yandell added a comment -

        svn ci -m "Applying Vincent Behar's second patch for LANG-419 - fixing a bug in abbreviate such that lower limits greater than the length of the string weren't working correctly" src

        Sending src/java/org/apache/commons/lang/WordUtils.java
        Sending src/test/org/apache/commons/lang/WordUtilsTest.java
        Transmitting file data ..
        Committed revision 655246.

        Show
        bayard Henri Yandell added a comment - svn ci -m "Applying Vincent Behar's second patch for LANG-419 - fixing a bug in abbreviate such that lower limits greater than the length of the string weren't working correctly" src Sending src/java/org/apache/commons/lang/WordUtils.java Sending src/test/org/apache/commons/lang/WordUtilsTest.java Transmitting file data .. Committed revision 655246.

          People

          • Assignee:
            Unassigned
            Reporter:
            v.behar Vincent Behar
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development