Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #11767, restore the original parameter pair instead of giving default value when doing URL.parse. #11781

Merged
merged 2 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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