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 ce8fd9ba46
commit 2e5dca2c5e
2 changed files with 25 additions and 17 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}