Skip to content

Commit 0d9b094

Browse files
authored
[2.7] Fix pond ignore in URLStrParser (#9465)
1 parent 55672e4 commit 0d9b094

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/URLStrParser.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ private static Map<String, String> parseDecodedParams(String str, int from) {
9595
*/
9696
private static URL parseURLBody(String fullURLStr, String decodedBody, Map<String, String> parameters) {
9797
int starIdx = 0, endIdx = decodedBody.length();
98+
// ignore the url content following '#'
99+
int poundIndex = decodedBody.indexOf('#');
100+
if (poundIndex != -1) {
101+
endIdx = poundIndex;
102+
}
103+
98104
String protocol = null;
99105
int protoEndIdx = decodedBody.indexOf("://");
100106
if (protoEndIdx >= 0) {
@@ -118,7 +124,7 @@ private static URL parseURLBody(String fullURLStr, String decodedBody, Map<Strin
118124
String path = null;
119125
int pathStartIdx = indexOf(decodedBody, '/', starIdx, endIdx);
120126
if (pathStartIdx >= 0) {
121-
path = decodedBody.substring(pathStartIdx + 1);
127+
path = decodedBody.substring(pathStartIdx + 1, endIdx);
122128
endIdx = pathStartIdx;
123129
}
124130

dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java

+30-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package org.apache.dubbo.common;
1818

1919
import org.apache.dubbo.common.utils.CollectionUtils;
20-
2120
import org.apache.dubbo.common.utils.StringUtils;
21+
2222
import org.junit.jupiter.api.Assertions;
2323
import org.junit.jupiter.api.Test;
2424

@@ -33,11 +33,11 @@
3333
import static org.hamcrest.CoreMatchers.equalTo;
3434
import static org.hamcrest.MatcherAssert.assertThat;
3535
import static org.junit.jupiter.api.Assertions.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.assertFalse;
3637
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3738
import static org.junit.jupiter.api.Assertions.assertNull;
3839
import static org.junit.jupiter.api.Assertions.assertSame;
3940
import static org.junit.jupiter.api.Assertions.assertTrue;
40-
import static org.junit.jupiter.api.Assertions.assertFalse;
4141
import static org.junit.jupiter.api.Assertions.fail;
4242

4343
public class URLTest {
@@ -339,6 +339,34 @@ public void test_valueOf_Exception_noProtocol() throws Exception {
339339
}
340340
}
341341

342+
@Test
343+
public void test_ignore_pond() {
344+
URL url = URL.valueOf("dubbo://admin:hello1234@10.20.130.230:20880/context/path#index?version=1.0.0&id=org.apache.dubbo.config.RegistryConfig#0");
345+
URL urlFromDecoder = URLStrParser.parseDecodedStr("dubbo://admin:hello1234@10.20.130.230:20880/context/path#index?version=1.0.0&id=org.apache.dubbo.config.RegistryConfig#0");
346+
347+
assertURLStrDecoder(url);
348+
349+
assertEquals("dubbo", url.getProtocol());
350+
assertEquals("admin", url.getUsername());
351+
assertEquals("hello1234", url.getPassword());
352+
assertEquals("10.20.130.230", url.getHost());
353+
assertEquals("10.20.130.230:20880", url.getAddress());
354+
assertEquals(20880, url.getPort());
355+
assertEquals("context/path", url.getPath());
356+
assertEquals(2, url.getParameters().size());
357+
assertEquals("org.apache.dubbo.config.RegistryConfig#0", url.getParameter("id"));
358+
359+
assertEquals("dubbo", urlFromDecoder.getProtocol());
360+
assertEquals("admin", urlFromDecoder.getUsername());
361+
assertEquals("hello1234", urlFromDecoder.getPassword());
362+
assertEquals("10.20.130.230", urlFromDecoder.getHost());
363+
assertEquals("10.20.130.230:20880", urlFromDecoder.getAddress());
364+
assertEquals(20880, urlFromDecoder.getPort());
365+
assertEquals("context/path", urlFromDecoder.getPath());
366+
assertEquals(2, urlFromDecoder.getParameters().size());
367+
assertEquals("org.apache.dubbo.config.RegistryConfig#0", urlFromDecoder.getParameter("id"));
368+
}
369+
342370
@Test
343371
public void test_getAddress() throws Exception {
344372
URL url1 = URL.valueOf("dubbo://admin:hello1234@10.20.130.230:20880/context/path?version=1.0.0&application=morgan");

0 commit comments

Comments
 (0)