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

zrlw pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.3 by this push:
     new eb2eb29536 Fix StringUtils.substringAfter to return empty string when 
separator is absent (#16350)
eb2eb29536 is described below

commit eb2eb29536f240f08e14b4cf7185d4b2f0ce9317
Author: yang <[email protected]>
AuthorDate: Wed Jun 24 11:19:55 2026 +0800

    Fix StringUtils.substringAfter to return empty string when separator is 
absent (#16350)
    
    Co-authored-by: zrlw <[email protected]>
---
 .../java/org/apache/dubbo/common/utils/StringUtils.java    |  2 +-
 .../org/apache/dubbo/common/utils/StringUtilsTest.java     | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java
index 477e550822..d140ed4454 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java
@@ -1308,7 +1308,7 @@ public final class StringUtils {
             return str;
         }
         int index = str.indexOf(separator);
-        return index == INDEX_NOT_FOUND ? str : str.substring(index + 1);
+        return index == INDEX_NOT_FOUND ? EMPTY_STRING : str.substring(index + 
1);
     }
 
     /**
diff --git 
a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StringUtilsTest.java 
b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StringUtilsTest.java
index 65317f38d8..b8250019de 100644
--- 
a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StringUtilsTest.java
+++ 
b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/StringUtilsTest.java
@@ -505,6 +505,20 @@ class StringUtilsTest {
         assertTrue(startsWithIgnoreCase("Dubbo.application.name", 
"dubbo.application."));
     }
 
+    @Test
+    void testSubstringAfter() {
+        // null or empty input is returned as-is
+        assertThat(StringUtils.substringAfter(null, ':'), is(nullValue()));
+        assertEquals("", StringUtils.substringAfter("", ':'));
+        // returns the substring after the first occurrence of the separator
+        assertEquals("b", StringUtils.substringAfter("a:b", ':'));
+        assertEquals("b:c", StringUtils.substringAfter("a:b:c", ':'));
+        // separator at the end leaves nothing after it
+        assertEquals("", StringUtils.substringAfter("ab:", ':'));
+        // when the separator is absent the Javadoc promises an empty string
+        assertEquals("", StringUtils.substringAfter("abc", ':'));
+    }
+
     @Test
     void testToBoolean() {
         // true representations

Reply via email to