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 61b37db84b25..d4b5143f7cce 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 @@ -278,7 +278,7 @@ private static boolean addParam(String str, boolean isEncoded, int nameStart, in String name = decodeComponent(str, nameStart, valueStart - 3, false, tempBuf); String value; if (valueStart >= valueEnd) { - value = name; + value = ""; } else { value = decodeComponent(str, valueStart, valueEnd, false, tempBuf); } @@ -291,7 +291,7 @@ private static boolean addParam(String str, boolean isEncoded, int nameStart, in String name = str.substring(nameStart, valueStart - 1); String value; if (valueStart >= valueEnd) { - value = name; + value = ""; } else { value = str.substring(valueStart, valueEnd); } diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/URLStrParserTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/URLStrParserTest.java index aea200130684..6fccf104b095 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/URLStrParserTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/URLStrParserTest.java @@ -44,6 +44,7 @@ class URLStrParserTest { testCases.add("file:/path/to/file.txt"); testCases.add("dubbo://fe80:0:0:0:894:aeec:f37d:23e1%en0/path?abc=abc"); testCases.add("dubbo://[fe80:0:0:0:894:aeec:f37d:23e1]:20880/path?abc=abc"); + testCases.add("nacos://192.168.1.1:8848?username=&password="); errorDecodedCases.add("dubbo:192.168.1.1"); errorDecodedCases.add("://192.168.1.1"); @@ -80,4 +81,4 @@ void testDecoded() { }); } -} \ No newline at end of file +} 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 a4400eebef70..334ec396843d 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 @@ -308,7 +308,7 @@ void test_valueOf_WithProtocolHost() throws Exception { assertEquals(3, url.getParameters().size()); assertEquals("1.0.0", url.getVersion()); assertEquals("morgan", url.getParameter("application")); - assertEquals("noValue", url.getParameter("noValue")); + assertEquals("", url.getParameter("noValue")); } // TODO Do not want to use spaces? See: DUBBO-502, URL class handles special conventions for special characters. @@ -325,10 +325,10 @@ void test_noValueKey() throws Exception { URL url = URL.valueOf("http://1.2.3.4:8080/path?k0=&k1=v1"); assertURLStrDecoder(url); - assertTrue(url.hasParameter("k0")); + assertFalse(url.hasParameter("k0")); - // If a Key has no corresponding Value, then the Key also used as the Value. - assertEquals("k0", url.getParameter("k0")); + // If a Key has no corresponding Value, then empty string used as the Value. + assertEquals("", url.getParameter("k0")); } @Test @@ -1047,7 +1047,7 @@ void testParameterContainPound() { @Test void test_valueOfHasNameWithoutValue() throws Exception { URL url = URL.valueOf("dubbo://admin:hello1234@10.20.130.230:20880/context/path?version=1.0.0&application=morgan&noValue"); - Assertions.assertEquals("noValue", url.getParameter("noValue")); + Assertions.assertEquals("", url.getParameter("noValue")); } @Test