From 9bcc87934e48430cc81639d8b589d6a059c67c81 Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Mon, 20 May 2024 15:54:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmock=E5=90=8E=E7=BD=AE=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=8F=82=E6=95=B0=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/utils/mock/MockScriptEngineUtils.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockScriptEngineUtils.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockScriptEngineUtils.java index fac020390a..c29cc4d006 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockScriptEngineUtils.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/mock/MockScriptEngineUtils.java @@ -132,6 +132,7 @@ public class MockScriptEngineUtils { if (StringUtils.equals(requestMockParams.getParamType(), MockRequestType.JSON.name())) { String jsonBody = requestMockParams.getRaw(); jsonBody = StringUtils.replace(jsonBody, "\n", ""); + jsonBody = StringUtils.replace(jsonBody, "\r", ""); jsonBody = StringUtils.replace(jsonBody, "\\", "\\\\"); jsonBody = StringUtils.replace(jsonBody, "\"", "\\\""); preScriptBuffer.append("vars.put(\"body.json\",\"").append(jsonBody).append("\");\n"); @@ -139,11 +140,14 @@ public class MockScriptEngineUtils { String xmlRaw = requestMockParams.getRaw(); xmlRaw = StringUtils.chomp(xmlRaw); xmlRaw = StringUtils.replace(xmlRaw, "\n", ""); + xmlRaw = StringUtils.replace(xmlRaw, "\r", ""); xmlRaw = StringUtils.replace(xmlRaw, "\\", "\\\\"); xmlRaw = StringUtils.replace(xmlRaw, "\"", "\\\""); preScriptBuffer.append("vars.put(\"body.xml\",\"").append(xmlRaw).append("\");\n"); } else if (StringUtils.equals(requestMockParams.getParamType(), MockRequestType.RAW.name())) { String bodyRowString = requestMockParams.getRaw(); + bodyRowString = StringUtils.replace(bodyRowString, "\n", ""); + bodyRowString = StringUtils.replace(bodyRowString, "\r", ""); bodyRowString = StringUtils.replace(bodyRowString, "\\", "\\\\").replace("\"", "\\\""); preScriptBuffer.append("vars.put(\"bodyRaw\",\"").append(bodyRowString).append("\");\n"); } @@ -209,6 +213,7 @@ public class MockScriptEngineUtils { String jsonRaw = requestMockParams.getRaw(); jsonRaw = StringUtils.chomp(jsonRaw); jsonRaw = StringUtils.replace(jsonRaw, "\n", ""); + jsonRaw = StringUtils.replace(jsonRaw, "\r", ""); jsonRaw = StringUtils.replace(jsonRaw, "\\", "\\\\"); jsonRaw = StringUtils.replace(jsonRaw, "\"", "\\\""); preScriptBuffer.append("vars[\"body.json\"]=\"").append(jsonRaw).append("\";\n"); @@ -216,11 +221,14 @@ public class MockScriptEngineUtils { String xmlRaw = requestMockParams.getRaw(); xmlRaw = StringUtils.chomp(xmlRaw); xmlRaw = StringUtils.replace(xmlRaw, "\n", ""); + xmlRaw = StringUtils.replace(xmlRaw, "\r", ""); xmlRaw = StringUtils.replace(xmlRaw, "\\", "\\\\"); xmlRaw = StringUtils.replace(xmlRaw, "\"", "\\\""); preScriptBuffer.append("vars[\"body.xml\"]=\"").append(xmlRaw).append("\";\n"); } else if (StringUtils.equals(requestMockParams.getParamType(), MockRequestType.RAW.name())) { String bodyRowString = requestMockParams.getRaw(); + bodyRowString = StringUtils.replace(bodyRowString, "\n", ""); + bodyRowString = StringUtils.replace(bodyRowString, "\r", ""); bodyRowString = StringUtils.replace(bodyRowString, "\\", "\\\\").replace("\"", "\\\""); preScriptBuffer.append("vars[\"bodyRaw\"]=\"").append(bodyRowString).append("\";\n"); }