Skip to content

Commit

Permalink
[LANG-1397] WordUtils.wrap throws StringIndexOutOfBoundsException when
Browse files Browse the repository at this point in the history
wrapLength is Integer.MAX_VALUE.
  • Loading branch information
tasanuma authored and garydgregory committed May 18, 2018
1 parent bd4066e commit 09ef69c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="LANG-1371" type="fix" dev="pschumacher" due-to="Dmitry Ovchinnikov">Fix TypeUtils#parameterize to work correctly with narrower-typed array</action>
<action issue="LANG-1370" type="fix" dev="kinow" due-to="Andre Dieb">Fix EventCountCircuitBreaker increment batch</action>
<action issue="LANG-1385" type="fix" dev="ggregory" due-to="Rohan Padhye">NumberUtils.createNumber() throws StringIndexOutOfBoundsException instead of NumberFormatException</action>
<action issue="LANG-1397" type="fix" dev="ggregory" due-to="Takanobu Asanuma">WordUtils.wrap throws StringIndexOutOfBoundsException when wrapLength is Integer.MAX_VALUE.</action>
<action issue="LANG-1367" type="update" dev="ggregory" due-to="Gary Gregory">ObjectUtils.identityToString(Object) and friends should allocate builders and buffers with a size</action>
<action issue="LANG-1352" type="add" dev="pschumacher" due-to="Ruslan Sibgatullin">EnumUtils.getEnumIgnoreCase and isValidEnumIgnoreCase methods added</action>
<action issue="LANG-1372" type="add" dev="pschumacher" due-to="Sérgio Ozaki">Add ToStringSummary annotation</action>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/apache/commons/lang3/text/WordUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ public static String wrap(final String str, int wrapLength, String newLineStr, f

while (offset < inputLineLength) {
int spaceToWrapAt = -1;
Matcher matcher = patternToWrapOn.matcher(str.substring(offset, Math.min(offset + wrapLength + 1, inputLineLength)));
Matcher matcher = patternToWrapOn.matcher(
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,11 @@ public void testLANG1292() throws Exception {
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",70);
}

@Test
public void testLANG1397() throws Exception {
// Prior to fix, this was throwing StringIndexOutOfBoundsException
WordUtils.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", Integer.MAX_VALUE);
}
}

0 comments on commit 09ef69c

Please sign in to comment.