This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 86659a223f change StringUtil endsWithIgnoreCase/startsWithIgnoreCase 
to use root locale
86659a223f is described below

commit 86659a223fef7c9911e74a4a94ae9e687cfef63e
Author: PJ Fanning <[email protected]>
AuthorDate: Fri Jun 12 10:57:39 2026 +0100

    change StringUtil endsWithIgnoreCase/startsWithIgnoreCase to use root locale
---
 .../main/java/org/apache/poi/util/StringUtil.java  | 32 +++++++++++++++++++---
 .../java/org/apache/poi/util/TestStringUtil.java   |  6 ++++
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/poi/src/main/java/org/apache/poi/util/StringUtil.java 
b/poi/src/main/java/org/apache/poi/util/StringUtil.java
index ad263c3355..26b887238e 100644
--- a/poi/src/main/java/org/apache/poi/util/StringUtil.java
+++ b/poi/src/main/java/org/apache/poi/util/StringUtil.java
@@ -334,18 +334,42 @@ public final class StringUtil {
 
     /**
      * Tests if the string starts with the specified prefix, ignoring case 
consideration.
+     * <p>
+     *     In POI 6.0.0, this was changed to use the root locale.
+     * </p>
      */
+    @Internal
     public static boolean startsWithIgnoreCase(String haystack, String prefix) 
{
-        return haystack.regionMatches(true, 0, prefix, 0, prefix.length());
+        if (haystack == null || prefix == null) {
+            return false;
+        }
+
+        int len = prefix.length();
+        if (len > haystack.length()) {
+            return false;
+        }
+
+        return equalsIgnoreCase(haystack.substring(0, len), prefix);
     }
 
     /**
      * Tests if the string ends with the specified suffix, ignoring case 
consideration.
+     * <p>
+     *     In POI 6.0.0, this was changed to use the root locale.
+     * </p>
      */
+    @Internal
     public static boolean endsWithIgnoreCase(String haystack, String suffix) {
-        int length = suffix.length();
-        int start = haystack.length() - length;
-        return haystack.regionMatches(true, start, suffix, 0, length);
+        if (suffix == null || haystack == null) {
+            return false;
+        }
+        int len = suffix.length();
+        if (len > haystack.length()) {
+            return false;
+        }
+        int start = haystack.length() - len;
+
+        return equalsIgnoreCase(haystack.substring(start), suffix);
     }
 
     /**
diff --git a/poi/src/test/java/org/apache/poi/util/TestStringUtil.java 
b/poi/src/test/java/org/apache/poi/util/TestStringUtil.java
index f8c5462738..2f46891b48 100644
--- a/poi/src/test/java/org/apache/poi/util/TestStringUtil.java
+++ b/poi/src/test/java/org/apache/poi/util/TestStringUtil.java
@@ -111,6 +111,9 @@ class TestStringUtil {
         assertTrue(StringUtil.startsWithIgnoreCase("APACHE POI", "Apache 
POI"), "different case");
         assertFalse(StringUtil.startsWithIgnoreCase(" Apache POI project", 
"Apache POI"), "leading whitespace should not be ignored");
         assertFalse(StringUtil.startsWithIgnoreCase("Apache", "Apache POI"), 
"shorter string");
+        assertFalse(StringUtil.startsWithIgnoreCase(null, null), "returns 
false when nulls involved");
+        assertFalse(StringUtil.startsWithIgnoreCase(null, "null"), "returns 
false when nulls involved");
+        assertFalse(StringUtil.startsWithIgnoreCase("null", null), "returns 
false when nulls involved");
     }
 
     @Test
@@ -120,6 +123,9 @@ class TestStringUtil {
         assertTrue(StringUtil.endsWithIgnoreCase("APACHE POI", "Apache POI"), 
"different case");
         assertFalse(StringUtil.endsWithIgnoreCase("Apache POI project ", 
"Apache POI"), "trailing whitespace should not be ignored");
         assertFalse(StringUtil.endsWithIgnoreCase("Apache", "Apache POI"), 
"shorter string");
+        assertFalse(StringUtil.endsWithIgnoreCase(null, null), "returns false 
when nulls involved");
+        assertFalse(StringUtil.endsWithIgnoreCase(null, "null"), "returns 
false when nulls involved");
+        assertFalse(StringUtil.endsWithIgnoreCase("null", null), "returns 
false when nulls involved");
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to