Uploaded image for project: 'Commons Text'
  1. Commons Text
  2. TEXT-111

WordUtils.wrap must calculate offset increment from wrapOn pattern length

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.2
    • 1.7
    • None

    Description

      WordUtils.wrap(...) allows to specify the "wrapOn" regular expression to be used as breakable characters. If this pattern is a zero width assertion or is longer than 1 charachter, then the output is wrong because the wrapping algorithm always skips one character (assuming the line break character has a width of 1).

      Example failing test:

      assertThat(WordUtils.wrap("abcdef", 2, "\n", false, "(?=d)")).isEqualTo("abc\ndef");
      // produces "abc\nef" instead
      

      Fix would be to change the 2 occurences of

      offset = spaceToWrapAt + 1;
      

      to

      offset = spaceToWrapAt + matcher.end() - matcher.start();
      

      thereby not advancing 1 character each time, but as many characters as were just matched.

      Attachments

        Issue Links

          Activity

            People

              kinow Bruno P. Kinoshita
              bananeweizen Michael Keppler
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m