From cc7508dd619edf4515216539c952871d0fc1e6ee Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Fri, 15 Apr 2022 11:58:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(fastjson):=20=E8=BD=ACJsonObject=E8=BF=87?= =?UTF-8?q?=E6=BB=A4key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 转JsonObject过滤key --- .../api/dto/definition/parse/Swagger3Parser.java | 2 +- .../main/java/io/metersphere/api/jmeter/TestResult.java | 2 +- .../io/metersphere/api/service/ApiAutomationService.java | 4 ++-- .../io/metersphere/api/service/ApiDefinitionService.java | 3 ++- .../api/service/ApiScenarioReportService.java | 3 ++- .../api/service/ApiScenarioReportStructureService.java | 5 +++-- .../metersphere/job/sechedule/SwaggerUrlImportJob.java | 3 ++- .../io/metersphere/log/utils/ApiDefinitionDiffUtil.java | 9 +++++---- .../log/utils/ApiTestEnvironmentDiffUtil.java | 5 +++-- 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java index 6e7e2ff5d7..1fa820f1d7 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/parse/Swagger3Parser.java @@ -649,7 +649,7 @@ public class Swagger3Parser extends SwaggerAbstractParser { // schema.put("example", param.getString("value")); // swaggerParam.setSchema(schema); // } - paramsList.add(JSON.parseObject(JSON.toJSONString(swaggerParam))); + paramsList.add(JSON.parseObject(JSON.toJSONString(swaggerParam),Feature.DisableSpecialKeyDetect)); } } } diff --git a/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java b/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java index 1ef5a0a537..9436674170 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/TestResult.java @@ -203,7 +203,7 @@ public class TestResult { } if (StringUtils.isNotEmpty(item.getScenario())) { - List id_names = JSON.parseObject(item.getScenario(), List.class); + List id_names = JSON.parseObject(item.getScenario(), List.class, Feature.DisableSpecialKeyDetect); this.setStatus(id_names, item.getError() > 0); return item.getScenario(); } else { diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 0fe90de68b..c8a1155b04 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -1378,7 +1378,7 @@ public class ApiAutomationService { if (scenario == null || StringUtils.isEmpty(scenario.getScenarioDefinition())) { return; } - JSONObject element = JSON.parseObject(scenario.getScenarioDefinition()); + JSONObject element = JSON.parseObject(scenario.getScenarioDefinition(),Feature.DisableSpecialKeyDetect); JSONArray hashTree = element.getJSONArray("hashTree"); ApiScenarioImportUtil.formatHashTree(hashTree); setHashTree(hashTree); @@ -1402,7 +1402,7 @@ public class ApiAutomationService { if (CollectionUtils.isEmpty(object.getJSONArray("hashTree"))) { ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(object.getString("id")); if (model != null) { - JSONObject element = JSON.parseObject(model.getRequest()); + JSONObject element = JSON.parseObject(model.getRequest(),Feature.DisableSpecialKeyDetect); object.put("hashTree", element.getJSONArray("hashTree")); } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index bd510afbf0..44204da3fd 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -2,6 +2,7 @@ package io.metersphere.api.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.api.dto.APIReportResult; @@ -1973,7 +1974,7 @@ public class ApiDefinitionService { ApiDefinitionWithBLOBs bloBs = apiDefinitionMapper.selectByPrimaryKey(id); List elements = new LinkedList<>(); if (bloBs != null && StringUtils.isNotEmpty(bloBs.getResponse())) { - JSONObject object = JSON.parseObject(bloBs.getResponse()); + JSONObject object = JSON.parseObject(bloBs.getResponse(), Feature.DisableSpecialKeyDetect); JSONObject body = (JSONObject) object.get("body"); if (body != null) { String raw = body.getString("raw"); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 90704019bc..2db3412cde 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -3,6 +3,7 @@ package io.metersphere.api.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import io.metersphere.api.dto.*; import io.metersphere.api.dto.automation.APIScenarioReportResult; import io.metersphere.api.dto.automation.ExecuteType; @@ -452,7 +453,7 @@ public class ApiScenarioReportService { String environmentType = apiScenario.getEnvironmentType(); if (StringUtils.equals(environmentType, EnvironmentType.JSON.name()) && StringUtils.isNotEmpty(apiScenario.getEnvironmentJson())) { String environmentJson = apiScenario.getEnvironmentJson(); - JSONObject jsonObject = JSON.parseObject(environmentJson); + JSONObject jsonObject = JSON.parseObject(environmentJson, Feature.DisableSpecialKeyDetect); ApiTestEnvironmentExample example = new ApiTestEnvironmentExample(); List collect = jsonObject.values().stream().map(Object::toString).collect(Collectors.toList()); collect.add("-1");// 防止没有配置环境导致不能发送的问题 diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java index bd58146173..854ad72720 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportStructureService.java @@ -3,6 +3,7 @@ package io.metersphere.api.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import io.metersphere.api.dto.ApiScenarioReportBaseInfoDTO; import io.metersphere.api.dto.ApiScenarioReportDTO; import io.metersphere.api.dto.RequestResultExpandDTO; @@ -122,7 +123,7 @@ public class ApiScenarioReportStructureService { } public static StepTreeDTO dataFormatting(String id, String name, String scenarioDefinition, String reportType) { - JSONObject element = JSON.parseObject(scenarioDefinition); + JSONObject element = JSON.parseObject(scenarioDefinition, Feature.DisableSpecialKeyDetect); StepTreeDTO dto = null; if (element != null && element.getBoolean("enable")) { element = getRefElement(element); @@ -150,7 +151,7 @@ public class ApiScenarioReportStructureService { if (StringUtils.equals(element.getString("type"), "scenario")) { ApiScenarioWithBLOBs scenarioWithBLOBs = CommonBeanFactory.getBean(ApiScenarioMapper.class).selectByPrimaryKey(element.getString("id")); if (scenarioWithBLOBs != null) { - return JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition()); + return JSON.parseObject(scenarioWithBLOBs.getScenarioDefinition(), Feature.DisableSpecialKeyDetect); } } } diff --git a/backend/src/main/java/io/metersphere/job/sechedule/SwaggerUrlImportJob.java b/backend/src/main/java/io/metersphere/job/sechedule/SwaggerUrlImportJob.java index de9912e51b..5a75ad1221 100644 --- a/backend/src/main/java/io/metersphere/job/sechedule/SwaggerUrlImportJob.java +++ b/backend/src/main/java/io/metersphere/job/sechedule/SwaggerUrlImportJob.java @@ -2,6 +2,7 @@ package io.metersphere.job.sechedule; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import io.metersphere.api.dto.ApiTestImportRequest; import io.metersphere.api.dto.definition.request.auth.MsAuthManager; import io.metersphere.api.dto.scenario.KeyValue; @@ -55,7 +56,7 @@ public class SwaggerUrlImportJob extends MsScheduleJob { public void setAuthInfo(String config, ApiTestImportRequest request){ // 获取鉴权设置 if(StringUtils.isNotBlank(config)){ - JSONObject configObj = JSON.parseObject(config); + JSONObject configObj = JSON.parseObject(config, Feature.DisableSpecialKeyDetect); List headers = JSONObject.parseArray(configObj.getString("headers"), KeyValue.class); if(CollectionUtils.isNotEmpty(headers)){ request.setHeaders(headers); diff --git a/backend/src/main/java/io/metersphere/log/utils/ApiDefinitionDiffUtil.java b/backend/src/main/java/io/metersphere/log/utils/ApiDefinitionDiffUtil.java index 1a31005ad9..21c954d3dd 100644 --- a/backend/src/main/java/io/metersphere/log/utils/ApiDefinitionDiffUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/ApiDefinitionDiffUtil.java @@ -2,6 +2,7 @@ package io.metersphere.log.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import io.metersphere.api.dto.definition.request.sampler.MsDubboSampler; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler; @@ -26,8 +27,8 @@ public class ApiDefinitionDiffUtil { public static String diffResponse(String newValue, String oldValue) { Map diffMap = new LinkedHashMap<>(); - JSONObject bloBsNew = JSON.parseObject(newValue); - JSONObject bloBsOld = JSON.parseObject(oldValue); + JSONObject bloBsNew = JSON.parseObject(newValue, Feature.DisableSpecialKeyDetect); + JSONObject bloBsOld = JSON.parseObject(oldValue, Feature.DisableSpecialKeyDetect); if (bloBsNew == null || StringUtils.isEmpty(bloBsNew.getString("type"))) { return null; } @@ -43,8 +44,8 @@ public class ApiDefinitionDiffUtil { public static String diff(String newValue, String oldValue) { try { - JSONObject bloBsNew = JSON.parseObject(newValue); - JSONObject bloBsOld = JSON.parseObject(oldValue); + JSONObject bloBsNew = JSON.parseObject(newValue, Feature.DisableSpecialKeyDetect); + JSONObject bloBsOld = JSON.parseObject(oldValue, Feature.DisableSpecialKeyDetect); if (bloBsNew == null || StringUtils.isEmpty(bloBsNew.getString("type"))) { return null; } diff --git a/backend/src/main/java/io/metersphere/log/utils/ApiTestEnvironmentDiffUtil.java b/backend/src/main/java/io/metersphere/log/utils/ApiTestEnvironmentDiffUtil.java index ee13ca3d8d..1c351dd52c 100644 --- a/backend/src/main/java/io/metersphere/log/utils/ApiTestEnvironmentDiffUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/ApiTestEnvironmentDiffUtil.java @@ -2,6 +2,7 @@ package io.metersphere.log.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.parser.Feature; import io.metersphere.commons.utils.LogUtil; import org.apache.commons.lang3.StringUtils; import java.util.LinkedHashMap; @@ -11,8 +12,8 @@ public class ApiTestEnvironmentDiffUtil { public static String diff(String newValue, String oldValue) { try { - JSONObject bloBsNew = JSON.parseObject(newValue); - JSONObject bloBsOld = JSON.parseObject(oldValue); + JSONObject bloBsNew = JSON.parseObject(newValue, Feature.DisableSpecialKeyDetect); + JSONObject bloBsOld = JSON.parseObject(oldValue, Feature.DisableSpecialKeyDetect); Map diffMap = new LinkedHashMap<>(); diffMap.put("type", "preAndPostScript");