Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.2
-
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
- relates to
-
TEXT-152 infinite loop in WordUtils.wrap
- Resolved
- links to