From 2e5dca2c5e5e6b518ba63e86090ad7ed5d11beda Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 10 Nov 2022 16:57:14 +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=8D=E5=9C=BA=E6=99=AF=E5=90=8D=E7=A7=B0=E5=90=AB?= =?UTF-8?q?=E6=9C=89=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=B5=8B=E8=AF=95=E6=8A=A5=E5=91=8A=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1019538 --user=赵勇 【接口测试】名称包含${,场景无法执行 https://www.tapd.cn/55049933/s/1294446 --- .../ExtApiDefinitionExecResultProvider.java | 20 ++++++++++------- .../ext/ExtApiScenarioReportProvider.java | 22 +++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java index c09ba605cd..f0142f9750 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionExecResultProvider.java @@ -16,7 +16,7 @@ public class ExtApiDefinitionExecResultProvider { .append("'") .append(result.getId()) .append("','") - .append(result.getName().replace("\'", "\\'")) + .append(translate(result.getName())) .append("','") .append(result.getResourceId()) .append("','") @@ -50,13 +50,9 @@ public class ExtApiDefinitionExecResultProvider { .append("','") .append(result.getEnvConfig()); //判断有没有关联的测试报告ID - if (StringUtils.isBlank(result.getRelevanceTestPlanReportId())) { - sqlList.append("', null"); - } else { - sqlList.append("','") - .append(result.getRelevanceTestPlanReportId()) - .append("'"); - } + sqlList.append("','") + .append(StringUtils.defaultIfBlank(result.getRelevanceTestPlanReportId(), "null")) + .append("'"); sqlList.append(")"); if (i < list.size() - 1) { sqlList.append(","); @@ -64,4 +60,12 @@ public class ExtApiDefinitionExecResultProvider { } return sqlList.toString(); } + + private String translate(String name) { + if (StringUtils.isNotBlank(name)) { + name = StringUtils.replace(name, "\'", "\\'"); + name = StringUtils.replace(name, "${", "$ {"); + } + return name; + } } diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java index 2717018fd5..733472c725 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioReportProvider.java @@ -18,7 +18,7 @@ public class ExtApiScenarioReportProvider { .append("','") .append(result.getProjectId()) .append("','") - .append(result.getName().replace("\'", "\\'")) + .append(translate(result.getName())) .append("',") .append(result.getCreateTime()) .append(",") @@ -32,7 +32,7 @@ public class ExtApiScenarioReportProvider { .append("','") .append(result.getExecuteType()) .append("','") - .append(result.getScenarioName().replace("\'", "\\'")) + .append(translate(result.getScenarioName())) .append("','") .append(result.getScenarioId()) .append("','") @@ -52,13 +52,9 @@ public class ExtApiScenarioReportProvider { .append("','") .append(result.getEnvConfig()); //判断有没有关联的测试报告ID - if (StringUtils.isBlank(result.getRelevanceTestPlanReportId())) { - sqlList.append("', null"); - } else { - sqlList.append("','") - .append(result.getRelevanceTestPlanReportId()) - .append("'"); - } + sqlList.append("','") + .append(StringUtils.defaultIfBlank(result.getRelevanceTestPlanReportId(), "null")) + .append("'"); sqlList.append(")"); if (i < list.size() - 1) { sqlList.append(","); @@ -66,4 +62,12 @@ public class ExtApiScenarioReportProvider { } return sqlList.toString(); } + + private String translate(String name) { + if (StringUtils.isNotBlank(name)) { + name = StringUtils.replace(name, "\'", "\\'"); + name = StringUtils.replace(name, "${", "$ {"); + } + return name; + } }