From 7390a1ec0ba3c1edb78f0b001a6da386577f20eb Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 3 Jun 2021 16:03:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DURL=20decode=20=E6=97=B6=E6=9C=89=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E5=AD=97=E7=AC=A6=20+=20=E6=97=B6=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/sampler/MsHTTPSamplerProxy.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 5e28698ccb..892f87faff 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -52,6 +52,7 @@ import org.apache.jorphan.collections.HashTree; import java.net.URL; import java.net.URLDecoder; +import java.net.URLEncoder; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -306,7 +307,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setPort(urlObject.getPort()); } sampler.setProtocol(urlObject.getProtocol()); - sampler.setPath(URLDecoder.decode(urlObject.getPath(), "UTF-8")); + sampler.setPath(URLDecoder.decode(URLEncoder.encode(urlObject.getPath(), "UTF-8"), "UTF-8")); } catch (Exception e) { LogUtil.error(e.getMessage(), e); } @@ -315,9 +316,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (isCustomizeReqCompleteUrl(this.path)) { url = httpConfig.getProtocol() + "://" + httpConfig.getSocket(); } - String envPath = ""; - if (!isCustomizeReqCompleteUrl(this.path)) { URL urlObject = new URL(url); envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath(); @@ -338,16 +337,16 @@ public class MsHTTPSamplerProxy extends MsTestElement { sampler.setDomain(URLDecoder.decode(urlObject.getHost(), "UTF-8")); sampler.setProtocol(urlObject.getProtocol()); } - sampler.setPath(URLDecoder.decode(envPath, "UTF-8")); + sampler.setPath(URLDecoder.decode(URLEncoder.encode(envPath, "UTF-8"), "UTF-8")); } } String envPath = sampler.getPath(); if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) { - envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8")); + envPath = getRestParameters(envPath); sampler.setPath(envPath); } if (CollectionUtils.isNotEmpty(this.getArguments())) { - String path = getPostQueryParameters(URLDecoder.decode(envPath, "UTF-8")); + String path = getPostQueryParameters(envPath); if (HTTPConstants.DELETE.equals(this.getMethod()) && !path.startsWith("${")) { if (!path.startsWith("/")) { path = "/" + path; @@ -359,7 +358,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { } path = sampler.getProtocol() + "://" + sampler.getDomain() + port + path; } - sampler.setProperty("HTTPSampler.path", URLDecoder.decode(path, "UTF-8")); + sampler.setProperty("HTTPSampler.path", path); } } else { String url = this.getUrl(); @@ -384,11 +383,11 @@ public class MsHTTPSamplerProxy extends MsTestElement { String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath(); sampler.setPath(envPath); if (CollectionUtils.isNotEmpty(this.getRest()) && this.isRest()) { - envPath = getRestParameters(URLDecoder.decode(envPath, "UTF-8")); + envPath = getRestParameters(URLDecoder.decode(URLEncoder.encode(envPath, "UTF-8"), "UTF-8")); sampler.setPath(envPath); } if (CollectionUtils.isNotEmpty(this.getArguments())) { - sampler.setPath(getPostQueryParameters(URLDecoder.decode(envPath, "UTF-8"))); + sampler.setPath(getPostQueryParameters(URLDecoder.decode(URLEncoder.encode(envPath, "UTF-8"), "UTF-8"))); } } } catch (Exception e) {