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

[2.7] Fix pond ignore in URLStrParser #9465

Merged
merged 1 commit into from Dec 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -95,6 +95,12 @@ private static Map<String, String> parseDecodedParams(String str, int from) {
*/
private static URL parseURLBody(String fullURLStr, String decodedBody, Map<String, String> parameters) {
int starIdx = 0, endIdx = decodedBody.length();
// ignore the url content following '#'
int poundIndex = decodedBody.indexOf('#');
if (poundIndex != -1) {
endIdx = poundIndex;
}

String protocol = null;
int protoEndIdx = decodedBody.indexOf("://");
if (protoEndIdx >= 0) {
Expand All @@ -118,7 +124,7 @@ private static URL parseURLBody(String fullURLStr, String decodedBody, Map<Strin
String path = null;
int pathStartIdx = indexOf(decodedBody, '/', starIdx, endIdx);
if (pathStartIdx >= 0) {
path = decodedBody.substring(pathStartIdx + 1);
path = decodedBody.substring(pathStartIdx + 1, endIdx);
endIdx = pathStartIdx;
}

Expand Down
32 changes: 30 additions & 2 deletions dubbo-common/src/test/java/org/apache/dubbo/common/URLTest.java
Expand Up @@ -17,8 +17,8 @@
package org.apache.dubbo.common;

import org.apache.dubbo.common.utils.CollectionUtils;

import org.apache.dubbo.common.utils.StringUtils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand All @@ -33,11 +33,11 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;

public class URLTest {
Expand Down Expand Up @@ -339,6 +339,34 @@ public void test_valueOf_Exception_noProtocol() throws Exception {
}
}

@Test
public void test_ignore_pond() {
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");
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");

assertURLStrDecoder(url);

assertEquals("dubbo", url.getProtocol());
assertEquals("admin", url.getUsername());
assertEquals("hello1234", url.getPassword());
assertEquals("10.20.130.230", url.getHost());
assertEquals("10.20.130.230:20880", url.getAddress());
assertEquals(20880, url.getPort());
assertEquals("context/path", url.getPath());
assertEquals(2, url.getParameters().size());
assertEquals("org.apache.dubbo.config.RegistryConfig#0", url.getParameter("id"));

assertEquals("dubbo", urlFromDecoder.getProtocol());
assertEquals("admin", urlFromDecoder.getUsername());
assertEquals("hello1234", urlFromDecoder.getPassword());
assertEquals("10.20.130.230", urlFromDecoder.getHost());
assertEquals("10.20.130.230:20880", urlFromDecoder.getAddress());
assertEquals(20880, urlFromDecoder.getPort());
assertEquals("context/path", urlFromDecoder.getPath());
assertEquals(2, urlFromDecoder.getParameters().size());
assertEquals("org.apache.dubbo.config.RegistryConfig#0", urlFromDecoder.getParameter("id"));
}

@Test
public void test_getAddress() throws Exception {
URL url1 = URL.valueOf("dubbo://admin:hello1234@10.20.130.230:20880/context/path?version=1.0.0&application=morgan");
Expand Down