From c8cefee04f82199646fe79b8b401d489d27d0e3b Mon Sep 17 00:00:00 2001 From: zhox <41657421+zhongxiongzeng@users.noreply.github.com> Date: Mon, 21 Jun 2021 10:32:34 +0800 Subject: [PATCH] improve the code of URLStrParser.java (#8085) --- .../java/org/apache/dubbo/common/URL.java | 2 +- .../org/apache/dubbo/common/URLStrParser.java | 36 +++++++------------ 2 files changed, 13 insertions(+), 25 deletions(-) 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 7b92f59ea7c..a2b4762b9ea 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 @@ -248,7 +248,7 @@ public static URL valueOf(String url) { Map parameters = null; int i = url.indexOf('?'); // separator between body and parameters if (i >= 0) { - String[] parts = url.substring(i + 1).split("&"); + String[] parts = url.substring(i + 1).split("[&;]"); parameters = new HashMap<>(); for (String part : parts) { part = part.trim(); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URLStrParser.java b/dubbo-common/src/main/java/org/apache/dubbo/common/URLStrParser.java index 06db68e7718..1a17d9faa28 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/URLStrParser.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URLStrParser.java @@ -224,32 +224,20 @@ private static boolean addParam(String str, boolean isEncoded, int nameStart, in valueStart = valueEnd + 1; } + String name; + String value; if (isEncoded) { - String name = decodeComponent(str, nameStart, valueStart - 3, false, tempBuf); - String value = decodeComponent(str, valueStart, valueEnd, false, tempBuf); - if (valueStart == valueEnd) { - value = name; - } else { - value = decodeComponent(str, valueStart, valueEnd, false, tempBuf); - } - params.put(name, value); - // compatible with lower versions registering "default." keys - if (name.startsWith(DEFAULT_KEY_PREFIX)) { - params.putIfAbsent(name.substring(DEFAULT_KEY_PREFIX.length()), value); - } + name = decodeComponent(str, nameStart, valueStart - 3, false, tempBuf); + value = valueStart == valueEnd ? name : decodeComponent(str, valueStart, valueEnd, false, tempBuf); } else { - String name = str.substring(nameStart, valueStart - 1); - String value = str.substring(valueStart, valueEnd); - if (valueStart == valueEnd) { - value = name; - } else { - value = str.substring(valueStart, valueEnd); - } - params.put(name, value); - // compatible with lower versions registering "default." keys - if (name.startsWith(DEFAULT_KEY_PREFIX)) { - params.putIfAbsent(name.substring(DEFAULT_KEY_PREFIX.length()), value); - } + name = str.substring(nameStart, valueStart - 1); + value = valueStart == valueEnd ? name : str.substring(valueStart, valueEnd); + } + + params.put(name, value); + // compatible with lower versions registering "default." keys + if (name.startsWith(DEFAULT_KEY_PREFIX)) { + params.putIfAbsent(name.substring(DEFAULT_KEY_PREFIX.length()), value); } return true; }