You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2020/04/03 04:38:54 UTC
[dubbo] branch master updated: compatible with lower versions
registering "default." keys (#5950)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new abd6e36 compatible with lower versions registering "default." keys (#5950)
abd6e36 is described below
commit abd6e36991390a95fa0b3094249eb860c3ea6dd5
Author: ken.lj <ke...@gmail.com>
AuthorDate: Fri Apr 3 12:38:28 2020 +0800
compatible with lower versions registering "default." keys (#5950)
---
dubbo-common/src/main/java/org/apache/dubbo/common/URL.java | 9 ++++++++-
.../java/org/apache/dubbo/common/utils/UrlUtilsTest.java | 13 +++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
index 1b90e37..e82cd63 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
@@ -43,6 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
+import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.HOST_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
@@ -250,7 +251,13 @@ class URL implements Serializable {
if (part.length() > 0) {
int j = part.indexOf('=');
if (j >= 0) {
- parameters.put(part.substring(0, j), part.substring(j + 1));
+ String key = part.substring(0, j);
+ String value = part.substring(j + 1);
+ parameters.put(key, value);
+ // compatible with lower versions registering "default." keys
+ if (key.startsWith(DEFAULT_KEY_PREFIX)) {
+ parameters.putIfAbsent(key.substring(DEFAULT_KEY_PREFIX.length()), value);
+ }
} else {
parameters.put(part, part);
}
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/UrlUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/UrlUtilsTest.java
index a116c69..a29c8e9 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/UrlUtilsTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/UrlUtilsTest.java
@@ -363,4 +363,17 @@ public class UrlUtilsTest {
assertTrue(UrlUtils.isMatchGlobPattern("v*e", "value"));
assertTrue(UrlUtils.isMatchGlobPattern("$key", "value", URL.valueOf("dubbo://localhost:8080/Foo?key=v*e")));
}
+
+ @Test
+ public void testIsMatchUrlWithDefaultPrefix() {
+ URL url = URL.valueOf("dubbo://127.0.0.1:20880/com.xxx.XxxService?default.version=1.0.0&default.group=test");
+ assertEquals("1.0.0", url.getParameter("version"));
+ assertEquals("1.0.0", url.getParameter("default.version"));
+
+ URL consumerUrl = URL.valueOf("consumer://127.0.0.1/com.xxx.XxxService?version=1.0.0&group=test");
+ assertTrue(UrlUtils.isMatch(consumerUrl, url));
+
+ URL consumerUrl1 = URL.valueOf("consumer://127.0.0.1/com.xxx.XxxService?default.version=1.0.0&default.group=test");
+ assertTrue(UrlUtils.isMatch(consumerUrl, url));
+ }
}