This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit c0159a85249651aa03c86780e7cbfe4104c615ac Author: Gary Gregory <[email protected]> AuthorDate: Wed Aug 12 11:46:12 2026 -0400 Sort members. --- .../commons/lang3/StringUtilsContainsTest.java | 60 +++++++++++----------- .../lang3/StringUtilsEqualsIndexOfTest.java | 26 +++++----- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java index 7f9de3ecd..5b59aa1dd 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsContainsTest.java @@ -122,6 +122,23 @@ void testContainsAny_StringCharArrayWithBadSupplementaryChars() { assertTrue(StringUtils.containsAny(CharU20001, CharUSuppCharHigh.toCharArray())); } + /** + * Two supplementary code points that share their low surrogate but not their high surrogate must not match, otherwise the low half of one pair is treated as + * the low half of the other. See https://www.oracle.com/technical-resources/articles/javase/supplementary.html + */ + @Test + void testContainsAny_StringCharArrayWithSharedLowSurrogate() { + // Sanity check: same low surrogate, different code point. + assertEquals(CharU20000.charAt(1), CharU24000.charAt(1)); + assertEquals(-1, CharU20000.indexOf(CharU24000)); + // Test: + assertFalse(StringUtils.containsAny(CharU20000, CharU24000.toCharArray())); + assertFalse(StringUtils.containsAny(CharU24000, CharU20000.toCharArray())); + assertFalse(StringUtils.containsAny("abc" + CharU20000 + "xyz", CharU24000.toCharArray())); + // A genuine occurrence of the same pair still matches. + assertTrue(StringUtils.containsAny("abc" + CharU24000 + "xyz", CharU24000.toCharArray())); + } + /** * See https://www.oracle.com/technical-resources/articles/javase/supplementary.html */ @@ -142,23 +159,6 @@ void testContainsAny_StringCharArrayWithSupplementaryChars() { assertFalse(StringUtils.containsAny(CharU20001, CharU20000.toCharArray())); } - /** - * Two supplementary code points that share their low surrogate but not their high surrogate must not match, otherwise the low half of one pair is treated as - * the low half of the other. See https://www.oracle.com/technical-resources/articles/javase/supplementary.html - */ - @Test - void testContainsAny_StringCharArrayWithSharedLowSurrogate() { - // Sanity check: same low surrogate, different code point. - assertEquals(CharU20000.charAt(1), CharU24000.charAt(1)); - assertEquals(-1, CharU20000.indexOf(CharU24000)); - // Test: - assertFalse(StringUtils.containsAny(CharU20000, CharU24000.toCharArray())); - assertFalse(StringUtils.containsAny(CharU24000, CharU20000.toCharArray())); - assertFalse(StringUtils.containsAny("abc" + CharU20000 + "xyz", CharU24000.toCharArray())); - // A genuine occurrence of the same pair still matches. - assertTrue(StringUtils.containsAny("abc" + CharU24000 + "xyz", CharU24000.toCharArray())); - } - @Test void testContainsAny_StringString() { assertFalse(StringUtils.containsAny(null, (String) null)); @@ -345,6 +345,19 @@ void testContainsNone_CharArrayWithBadSupplementaryChars() { assertFalse(StringUtils.containsNone(CharU20001, CharUSuppCharHigh.toCharArray())); } + /** + * Two supplementary code points that share their low surrogate but not their high surrogate must not match. See + * https://www.oracle.com/technical-resources/articles/javase/supplementary.html + */ + @Test + void testContainsNone_CharArrayWithSharedLowSurrogate() { + assertEquals(CharU20000.charAt(1), CharU24000.charAt(1)); + assertTrue(StringUtils.containsNone(CharU20000, CharU24000.toCharArray())); + assertTrue(StringUtils.containsNone(CharU24000, CharU20000.toCharArray())); + // A genuine occurrence of the same pair is still found. + assertFalse(StringUtils.containsNone("abc" + CharU24000, CharU24000.toCharArray())); + } + /** * See https://www.oracle.com/technical-resources/articles/javase/supplementary.html */ @@ -362,19 +375,6 @@ void testContainsNone_CharArrayWithSupplementaryChars() { assertTrue(StringUtils.containsNone(CharU20001, CharU20000.toCharArray())); } - /** - * Two supplementary code points that share their low surrogate but not their high surrogate must not match. See - * https://www.oracle.com/technical-resources/articles/javase/supplementary.html - */ - @Test - void testContainsNone_CharArrayWithSharedLowSurrogate() { - assertEquals(CharU20000.charAt(1), CharU24000.charAt(1)); - assertTrue(StringUtils.containsNone(CharU20000, CharU24000.toCharArray())); - assertTrue(StringUtils.containsNone(CharU24000, CharU20000.toCharArray())); - // A genuine occurrence of the same pair is still found. - assertFalse(StringUtils.containsNone("abc" + CharU24000, CharU24000.toCharArray())); - } - @Test void testContainsNone_String() { final String str1 = "a"; diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java index 1b78d9e36..70d592f58 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java @@ -403,6 +403,19 @@ void testIndexOfAny_StringCharArray() { assertEquals(0, StringUtils.indexOfAny("cbda", 'a', 'b', 'c', 'd')); } + /** + * A low surrogate that is the low half of a supplementary code point in the search set must not match the low half of a different code point in the input, + * otherwise the returned index points inside a surrogate pair. See https://www.oracle.com/technical-resources/articles/javase/supplementary.html + */ + @Test + void testIndexOfAny_StringCharArrayWithSharedLowSurrogate() { + assertEquals(CharU20000.charAt(1), CharU24000.charAt(1)); + assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU24000.toCharArray())); + assertEquals(-1, StringUtils.indexOfAny("abc" + CharU20000, CharU24000.toCharArray())); + // A genuine occurrence of the same pair is found at the start of the pair. + assertEquals(3, StringUtils.indexOfAny("abc" + CharU24000, CharU24000.toCharArray())); + } + /** * See https://www.oracle.com/technical-resources/articles/javase/supplementary.html */ @@ -418,19 +431,6 @@ void testIndexOfAny_StringCharArrayWithSupplementaryChars() { assertEquals(-1, StringUtils.indexOfAny("abc" + CharUSuppCharHigh, CharU20000.toCharArray())); } - /** - * A low surrogate that is the low half of a supplementary code point in the search set must not match the low half of a different code point in the input, - * otherwise the returned index points inside a surrogate pair. See https://www.oracle.com/technical-resources/articles/javase/supplementary.html - */ - @Test - void testIndexOfAny_StringCharArrayWithSharedLowSurrogate() { - assertEquals(CharU20000.charAt(1), CharU24000.charAt(1)); - assertEquals(-1, StringUtils.indexOfAny(CharU20000, CharU24000.toCharArray())); - assertEquals(-1, StringUtils.indexOfAny("abc" + CharU20000, CharU24000.toCharArray())); - // A genuine occurrence of the same pair is found at the start of the pair. - assertEquals(3, StringUtils.indexOfAny("abc" + CharU24000, CharU24000.toCharArray())); - } - @Test void testIndexOfAny_StringIntCharArray() { // default cases
