修复特殊字符问题

This commit is contained in:
q4speed 2020-05-21 14:17:55 +08:00
parent 5c75349171
commit e342112b6f
2 changed files with 20 additions and 6 deletions

View File

@ -279,7 +279,7 @@ export class HTTPSamplerArguments extends Element {
let collectionProp = this.collectionProp('Arguments.arguments'); let collectionProp = this.collectionProp('Arguments.arguments');
this.args.forEach(arg => { this.args.forEach(arg => {
let elementProp = collectionProp.elementProp(arg.name, 'HTTPArgument'); 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); elementProp.boolProp('HTTPArgument.use_equals', arg.equals || true);
if (arg.name) { if (arg.name) {
elementProp.stringProp('Argument.name', arg.name); elementProp.stringProp('Argument.name', arg.name);

View File

@ -456,7 +456,7 @@ class JMXGenerator {
} }
addScenarioVariables(threadGroup, scenario) { addScenarioVariables(threadGroup, scenario) {
let args = scenario.variables.filter(this.filter) let args = this.replaceKV(scenario.variables);
if (args.length > 0) { if (args.length > 0) {
let name = scenario.name + " Variables" let name = scenario.name + " Variables"
threadGroup.put(new Arguments(name, args)); threadGroup.put(new Arguments(name, args));
@ -464,7 +464,7 @@ class JMXGenerator {
} }
addScenarioHeaders(threadGroup, scenario) { addScenarioHeaders(threadGroup, scenario) {
let headers = scenario.headers.filter(this.filter) let headers = this.replaceKV(scenario.headers);
if (headers.length > 0) { if (headers.length > 0) {
let name = scenario.name + " Headers" let name = scenario.name + " Headers"
threadGroup.put(new HeaderManager(name, headers)); threadGroup.put(new HeaderManager(name, headers));
@ -473,14 +473,14 @@ class JMXGenerator {
addRequestHeader(httpSamplerProxy, request) { addRequestHeader(httpSamplerProxy, request) {
let name = request.name + " Headers"; let name = request.name + " Headers";
let headers = request.headers.filter(this.filter); let headers = this.replaceKV(request.headers);
if (headers.length > 0) { if (headers.length > 0) {
httpSamplerProxy.put(new HeaderManager(name, headers)); httpSamplerProxy.put(new HeaderManager(name, headers));
} }
} }
addRequestArguments(httpSamplerProxy, request) { addRequestArguments(httpSamplerProxy, request) {
let args = request.parameters.filter(this.filter) let args = this.replaceKV(request.parameters);
if (args.length > 0) { if (args.length > 0) {
httpSamplerProxy.add(new HTTPSamplerArguments(args)); httpSamplerProxy.add(new HTTPSamplerArguments(args));
} }
@ -514,7 +514,7 @@ class JMXGenerator {
getAssertion(regex) { getAssertion(regex) {
let name = regex.description; let name = regex.description;
let type = JMX_ASSERTION_CONDITION.CONTAINS; // 固定用Match自己写正则 let type = JMX_ASSERTION_CONDITION.CONTAINS; // 固定用Match自己写正则
let value = regex.expression; let value = this.replace(regex.expression);
switch (regex.subject) { switch (regex.subject) {
case ASSERTION_REGEX_SUBJECT.RESPONSE_CODE: case ASSERTION_REGEX_SUBJECT.RESPONSE_CODE:
return new ResponseCodeAssertion(name, type, value); return new ResponseCodeAssertion(name, type, value);
@ -577,6 +577,20 @@ class JMXGenerator {
return config.isValid(); return config.isValid();
} }
replace(str) {
return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&apos;").replace(/"/g, "&quot;");
}
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() { toXML() {
let xml = '<?xml version="1.0" encoding="UTF-8"?>\n'; let xml = '<?xml version="1.0" encoding="UTF-8"?>\n';
xml += this.jmeterTestPlan.toXML(); xml += this.jmeterTestPlan.toXML();