ppkarwasz commented on code in PR #1649:
URL: https://github.com/apache/commons-lang/pull/1649#discussion_r3255263385


##########
src/main/java/org/apache/commons/lang3/text/WordUtils.java:
##########
@@ -652,21 +652,19 @@ public static String wrap(final String str, int 
wrapLength, String newLineStr, f
                 str.substring(offset, Math.min((int) 
Math.min(Integer.MAX_VALUE, offset + wrapLength + 1L), inputLineLength)));
             if (matcher.find()) {
                 if (matcher.start() == 0) {
-                    offset += matcher.end();
+                    // If the match is zero-width, advance by at least 1 to 
avoid infinite loop.
+                    offset += matcher.end() > 0 ? matcher.end() : 1;

Review Comment:
   This stops the infinite loop, but drops the first character of the line.
   
   Fixing this would require fixing a couple of other lines that assume matches 
are always of length 1. I am not sure if it is worth fixing in a **deprecated** 
method, but we should add some tests for variable-length matches in Commons 
Text.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to