You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/09/20 15:03:06 UTC

[dubbo] branch master updated: fix StringIndexOutOfBoundsException at addParam() (#8801)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5313bee  fix StringIndexOutOfBoundsException at addParam() (#8801)
5313bee is described below

commit 5313beec34b4fa53eb6e156ecef5cd5f4ecdd9e7
Author: zrlw <zr...@sina.com>
AuthorDate: Mon Sep 20 23:02:50 2021 +0800

    fix StringIndexOutOfBoundsException at addParam() (#8801)
---
 .../src/main/java/org/apache/dubbo/common/URLStrParser.java        | 4 ++--
 dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java    | 7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URLStrParser.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URLStrParser.java
index 1a17d9f..592cdc5 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URLStrParser.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URLStrParser.java
@@ -228,10 +228,10 @@ public final class URLStrParser {
         String value;
         if (isEncoded) {
             name = decodeComponent(str, nameStart, valueStart - 3, false, tempBuf);
-            value = valueStart == valueEnd ? name : decodeComponent(str, valueStart, valueEnd, false, tempBuf);
+            value = valueStart >= valueEnd ? name : decodeComponent(str, valueStart, valueEnd, false, tempBuf);
         } else {
             name = str.substring(nameStart, valueStart - 1);
-            value = valueStart == valueEnd ? name : str.substring(valueStart, valueEnd);
+            value = valueStart >= valueEnd ? name : str.substring(valueStart, valueEnd);
         }
 
         params.put(name, value);
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java
index 8ea1c7b..d5381f5 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java
@@ -1112,4 +1112,11 @@ public class URLTest {
         assertEquals(shortNumNotExist, 15);
         assertEquals(bNotExist, 16);
     }
+
+    @Test
+    public void test_valueOfHasNameWithoutValue() throws Exception {
+        String decodedURLStr = "dubbo://admin:hello1234@10.20.130.230:20880/context/path?version=1.0.0&application=morgan&noValue";
+        URL url = URLStrParser.parseDecodedStr(decodedURLStr);
+        Assertions.assertEquals("noValue", url.getParameter("noValue"));
+    }
 }