From e342112b6f33b0d9d3c39f2f65d15756abd00f2a Mon Sep 17 00:00:00 2001 From: q4speed Date: Thu, 21 May 2020 14:17:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=89=B9=E6=AE=8A=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/components/api/test/model/JMX.js | 2 +- .../api/test/model/ScenarioModel.js | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/frontend/src/business/components/api/test/model/JMX.js b/frontend/src/business/components/api/test/model/JMX.js index 5e5aad36a8..25d8356028 100644 --- a/frontend/src/business/components/api/test/model/JMX.js +++ b/frontend/src/business/components/api/test/model/JMX.js @@ -279,7 +279,7 @@ export class HTTPSamplerArguments extends Element { let collectionProp = this.collectionProp('Arguments.arguments'); this.args.forEach(arg => { let elementProp = collectionProp.elementProp(arg.name, 'HTTPArgument'); - elementProp.boolProp('HTTPArgument.always_encode', arg.encode || false); + elementProp.boolProp('HTTPArgument.always_encode', arg.encode || true); elementProp.boolProp('HTTPArgument.use_equals', arg.equals || true); if (arg.name) { elementProp.stringProp('Argument.name', arg.name); diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index 46e56647ac..03c4a226d6 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -456,7 +456,7 @@ class JMXGenerator { } addScenarioVariables(threadGroup, scenario) { - let args = scenario.variables.filter(this.filter) + let args = this.replaceKV(scenario.variables); if (args.length > 0) { let name = scenario.name + " Variables" threadGroup.put(new Arguments(name, args)); @@ -464,7 +464,7 @@ class JMXGenerator { } addScenarioHeaders(threadGroup, scenario) { - let headers = scenario.headers.filter(this.filter) + let headers = this.replaceKV(scenario.headers); if (headers.length > 0) { let name = scenario.name + " Headers" threadGroup.put(new HeaderManager(name, headers)); @@ -473,14 +473,14 @@ class JMXGenerator { addRequestHeader(httpSamplerProxy, request) { let name = request.name + " Headers"; - let headers = request.headers.filter(this.filter); + let headers = this.replaceKV(request.headers); if (headers.length > 0) { httpSamplerProxy.put(new HeaderManager(name, headers)); } } addRequestArguments(httpSamplerProxy, request) { - let args = request.parameters.filter(this.filter) + let args = this.replaceKV(request.parameters); if (args.length > 0) { httpSamplerProxy.add(new HTTPSamplerArguments(args)); } @@ -514,7 +514,7 @@ class JMXGenerator { getAssertion(regex) { let name = regex.description; let type = JMX_ASSERTION_CONDITION.CONTAINS; // 固定用Match,自己写正则 - let value = regex.expression; + let value = this.replace(regex.expression); switch (regex.subject) { case ASSERTION_REGEX_SUBJECT.RESPONSE_CODE: return new ResponseCodeAssertion(name, type, value); @@ -577,6 +577,20 @@ class JMXGenerator { return config.isValid(); } + replace(str) { + return str.replace(/&/g, "&").replace(//g, ">").replace(/'/g, "'").replace(/"/g, """); + } + + replaceKV(kvs) { + let results = []; + kvs.filter(this.filter).forEach(kv => { + let name = this.replace(kv.name); + let value = this.replace(kv.value); + results.push(new KeyValue(name, value)); + }); + return results; + } + toXML() { let xml = '\n'; xml += this.jmeterTestPlan.toXML();