[LANG-123] WordUtils.wrap throws StringIndexOutOfBoundsException when wrapLength is Integer.MAX_VALUE.
Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/c86c6e44 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/c86c6e44 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/c86c6e44 Branch: refs/heads/release Commit: c86c6e4458d5fa2872f851e972fea70cba302dc4 Parents: 280bccb Author: Gary Gregory <garydgreg...@gmail.com> Authored: Fri May 18 11:58:31 2018 -0600 Committer: Gary Gregory <garydgreg...@gmail.com> Committed: Fri May 18 11:58:31 2018 -0600 ---------------------------------------------------------------------- src/changes/changes.xml | 1 + src/main/java/org/apache/commons/text/WordUtils.java | 4 ++-- src/test/java/org/apache/commons/text/WordUtilsTest.java | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-text/blob/c86c6e44/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 932c131..74a95b1 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -50,6 +50,7 @@ The <action> type attribute can be add,update,fix,remove. <action issue="TEXT-119" type="fix" dev="pschumacher">Remove mention of SQL escaping from user guide</action> <action issue="TEXT-121" type="update" dev="ggregory" due-to="pschumacher">Update Java requirement from version 7 to 8.</action> <action issue="TEXT-122" type="update" dev="ggregory">Allow full customization with new API org.apache.commons.text.lookup.StringLookupFactory.interpolatorStringLookup(Map<String, StringLookup>, StringLookup, boolean).</action> + <action issue="LANG-123" type="fix" dev="ggregory" due-to="Takanobu Asanuma">WordUtils.wrap throws StringIndexOutOfBoundsException when wrapLength is Integer.MAX_VALUE.</action> </release> <release version="1.3" date="2018-03-16" description="Release 1.3"> http://git-wip-us.apache.org/repos/asf/commons-text/blob/c86c6e44/src/main/java/org/apache/commons/text/WordUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/WordUtils.java b/src/main/java/org/apache/commons/text/WordUtils.java index 259bde3..4cd078c 100644 --- a/src/main/java/org/apache/commons/text/WordUtils.java +++ b/src/main/java/org/apache/commons/text/WordUtils.java @@ -304,8 +304,8 @@ public class WordUtils { 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(); http://git-wip-us.apache.org/repos/asf/commons-text/blob/c86c6e44/src/test/java/org/apache/commons/text/WordUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/WordUtilsTest.java b/src/test/java/org/apache/commons/text/WordUtilsTest.java index 18d6eb9..416e3d3 100644 --- a/src/test/java/org/apache/commons/text/WordUtilsTest.java +++ b/src/test/java/org/apache/commons/text/WordUtilsTest.java @@ -528,6 +528,13 @@ public class WordUtilsTest { } @Test + public void testLANG1397() throws Exception { + // Prior to fix, this was throwing StringIndexOutOfBoundsException + WordUtils.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " + + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", Integer.MAX_VALUE); + } + + @Test public void testContainsAllWordsWithNull() { assertThat(WordUtils.containsAllWords("M", null)).isFalse(); }