diff --git a/src/main/java/org/apache/commons/lang3/text/WordUtils.java b/src/main/java/org/apache/commons/lang3/text/WordUtils.java index b38cb0fed..c61931299 100644 --- a/src/main/java/org/apache/commons/lang3/text/WordUtils.java +++ b/src/main/java/org/apache/commons/lang3/text/WordUtils.java @@ -565,6 +565,7 @@ public class WordUtils { return new String(buf, 0, count); } + //----------------------------------------------------------------------- /** *
Checks if the String contains all words in the given array.
* @@ -587,12 +588,14 @@ public class WordUtils { * @param words The array of String words to search for, may be null * @return {@code true} if all search words are found, {@code false} otherwise */ - public static boolean containsAllWords(String word, String... words) { - if (StringUtils.isEmpty(word) || ArrayUtils.isEmpty(words) - || (words.length == 1 && StringUtils.isBlank(words[0]))) { + public static boolean containsAllWords(CharSequence word, CharSequence... words) { + if (StringUtils.isEmpty(word) || ArrayUtils.isEmpty(words)) { return false; } - for (String w : words) { + for (CharSequence w : words) { + if (StringUtils.isBlank(w)) { + return false; + } Pattern p = Pattern.compile(".*\\b" + w + "\\b.*"); if (!p.matcher(word).matches()) { return false; diff --git a/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java b/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java index f905a52c6..92d697118 100644 --- a/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java @@ -236,6 +236,7 @@ public class WordUtilsTest { assertFalse(WordUtils.containsAllWords("zzabyycdxx", "by")); assertTrue(WordUtils.containsAllWords("lorem ipsum dolor sit amet", "ipsum", "lorem", "dolor")); assertFalse(WordUtils.containsAllWords("lorem ipsum dolor sit amet", "ipsum", null, "lorem", "dolor")); + assertFalse(WordUtils.containsAllWords("lorem ipsum null dolor sit amet", "ipsum", null, "lorem", "dolor")); assertFalse(WordUtils.containsAllWords("ab", "b")); assertFalse(WordUtils.containsAllWords("ab", "z")); }