fix(接口测试): 修复场景名称含有特殊字符导致生成测试报告失败问题

--bug=1019538 --user=赵勇 【接口测试】名称包含${,场景无法执行 https://www.tapd.cn/55049933/s/1294446
This commit is contained in:
fit2-zhao 2022-11-10 16:57:14 +08:00 committed by f2c-ci-robot[bot]
parent ad11cc380b
commit 091242bf09
2 changed files with 25 additions and 17 deletions

View File

@ -16,7 +16,7 @@ public class ExtApiDefinitionExecResultProvider {
.append("'") .append("'")
.append(result.getId()) .append(result.getId())
.append("','") .append("','")
.append(result.getName().replace("\'", "\\'")) .append(translate(result.getName()))
.append("','") .append("','")
.append(result.getResourceId()) .append(result.getResourceId())
.append("','") .append("','")
@ -50,13 +50,9 @@ public class ExtApiDefinitionExecResultProvider {
.append("','") .append("','")
.append(result.getEnvConfig()); .append(result.getEnvConfig());
//判断有没有关联的测试报告ID //判断有没有关联的测试报告ID
if (StringUtils.isBlank(result.getRelevanceTestPlanReportId())) { sqlList.append("','")
sqlList.append("', null"); .append(StringUtils.defaultIfBlank(result.getRelevanceTestPlanReportId(), "null"))
} else { .append("'");
sqlList.append("','")
.append(result.getRelevanceTestPlanReportId())
.append("'");
}
sqlList.append(")"); sqlList.append(")");
if (i < list.size() - 1) { if (i < list.size() - 1) {
sqlList.append(","); sqlList.append(",");
@ -64,4 +60,12 @@ public class ExtApiDefinitionExecResultProvider {
} }
return sqlList.toString(); return sqlList.toString();
} }
private String translate(String name) {
if (StringUtils.isNotBlank(name)) {
name = StringUtils.replace(name, "\'", "\\'");
name = StringUtils.replace(name, "${", "$ {");
}
return name;
}
} }

View File

@ -18,7 +18,7 @@ public class ExtApiScenarioReportProvider {
.append("','") .append("','")
.append(result.getProjectId()) .append(result.getProjectId())
.append("','") .append("','")
.append(result.getName().replace("\'", "\\'")) .append(translate(result.getName()))
.append("',") .append("',")
.append(result.getCreateTime()) .append(result.getCreateTime())
.append(",") .append(",")
@ -32,7 +32,7 @@ public class ExtApiScenarioReportProvider {
.append("','") .append("','")
.append(result.getExecuteType()) .append(result.getExecuteType())
.append("','") .append("','")
.append(result.getScenarioName().replace("\'", "\\'")) .append(translate(result.getScenarioName()))
.append("','") .append("','")
.append(result.getScenarioId()) .append(result.getScenarioId())
.append("','") .append("','")
@ -52,13 +52,9 @@ public class ExtApiScenarioReportProvider {
.append("','") .append("','")
.append(result.getEnvConfig()); .append(result.getEnvConfig());
//判断有没有关联的测试报告ID //判断有没有关联的测试报告ID
if (StringUtils.isBlank(result.getRelevanceTestPlanReportId())) { sqlList.append("','")
sqlList.append("', null"); .append(StringUtils.defaultIfBlank(result.getRelevanceTestPlanReportId(), "null"))
} else { .append("'");
sqlList.append("','")
.append(result.getRelevanceTestPlanReportId())
.append("'");
}
sqlList.append(")"); sqlList.append(")");
if (i < list.size() - 1) { if (i < list.size() - 1) {
sqlList.append(","); sqlList.append(",");
@ -66,4 +62,12 @@ public class ExtApiScenarioReportProvider {
} }
return sqlList.toString(); return sqlList.toString();
} }
private String translate(String name) {
if (StringUtils.isNotBlank(name)) {
name = StringUtils.replace(name, "\'", "\\'");
name = StringUtils.replace(name, "${", "$ {");
}
return name;
}
} }