diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java index 62b529197..4d0d8c558 100644 --- a/src/java/org/apache/commons/lang/StringUtils.java +++ b/src/java/org/apache/commons/lang/StringUtils.java @@ -2197,7 +2197,7 @@ public class StringUtils { * StringUtils.splitPreserveAllTokens(null, *) = null * StringUtils.splitPreserveAllTokens("", *) = [] * StringUtils.splitPreserveAllTokens("a.b.c", '.') = ["a", "b", "c"] - * StringUtils.splitPreserveAllTokens("a..b.c", '.') = ["a", "b", "c"] + * StringUtils.splitPreserveAllTokens("a..b.c", '.') = ["a", "", "b", "c"] * StringUtils.splitPreserveAllTokens("a:b:c", '.') = ["a:b:c"] * StringUtils.splitPreserveAllTokens("a\tb\nc", null) = ["a", "b", "c"] * StringUtils.splitPreserveAllTokens("a b c", ' ') = ["a", "b", "c"] diff --git a/src/test/org/apache/commons/lang/StringUtilsTest.java b/src/test/org/apache/commons/lang/StringUtilsTest.java index 59a995338..d36dcc045 100644 --- a/src/test/org/apache/commons/lang/StringUtilsTest.java +++ b/src/test/org/apache/commons/lang/StringUtilsTest.java @@ -581,6 +581,16 @@ public class StringUtilsTest extends TestCase { assertEquals("b", res[3]); assertEquals("c", res[4]); + // Match example in javadoc + { + String[] results = null; + String[] expectedResults = {"a", "", "b", "c"}; + results = StringUtils.splitPreserveAllTokens("a..b.c",'.'); + assertEquals(expectedResults.length, results.length); + for (int i = 0; i < expectedResults.length; i++) { + assertEquals(expectedResults[i], results[i]); + } + } } public void testSplitPreserveAllTokens_StringString_StringStringInt() { @@ -710,6 +720,7 @@ public class StringUtilsTest extends TestCase { assertEquals(expectedResults[i], results[i]); } } + } private void innerTestSplitPreserveAllTokens(char separator, String sepStr, char noMatch) {