Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoyoung authored and lcb11 committed Mar 31, 2023
1 parent d210527 commit a8df3bd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -80,4 +81,4 @@ void testDecoded() {
});
}

}
}
10 changes: 5 additions & 5 deletions dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a8df3bd

Please sign in to comment.