mirror of https://github.com/apache/jmeter.git
Escape commata in parameters when constructing function strings in the GUI function helper.
Bugzilla Id: 62478
git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1834192 13f79535-47bb-0310-9956-ffa450edef68
Former-commit-id: a7126c7e17
This commit is contained in:
parent
77a4fcff0f
commit
dd6c5dec7a
|
|
@ -175,9 +175,25 @@ public class FunctionHelper extends JDialog implements ActionListener, ChangeLis
|
|||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
StringBuilder functionCall = new StringBuilder("${");
|
||||
functionCall.append(functionList.getText());
|
||||
String functionName = functionList.getText();
|
||||
Arguments args = (Arguments) parameterPanel.createTestElement();
|
||||
String functionCall = buildFunctionCallString(functionName, args);
|
||||
cutPasteFunction.setText(functionCall);
|
||||
GuiUtils.copyTextToClipboard(cutPasteFunction.getText());
|
||||
CompoundVariable function = new CompoundVariable(functionCall);
|
||||
try {
|
||||
resultTextArea.setText(function.execute().trim());
|
||||
} catch(Exception ex) {
|
||||
log.error("Error calling function {}", functionCall, ex);
|
||||
resultTextArea.setText(ex.getMessage() + ", \nstacktrace:\n "+
|
||||
ExceptionUtils.getStackTrace(ex));
|
||||
resultTextArea.setCaretPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
private String buildFunctionCallString(String functionName, Arguments args) {
|
||||
StringBuilder functionCall = new StringBuilder("${");
|
||||
functionCall.append(functionName);
|
||||
if (args.getArguments().size() > 0) {
|
||||
functionCall.append("(");
|
||||
PropertyIterator iter = args.iterator();
|
||||
|
|
@ -187,23 +203,13 @@ public class FunctionHelper extends JDialog implements ActionListener, ChangeLis
|
|||
if (!first) {
|
||||
functionCall.append(",");
|
||||
}
|
||||
functionCall.append(arg.getValue());
|
||||
functionCall.append(arg.getValue().replaceAll(",", "\\\\,"));
|
||||
first = false;
|
||||
}
|
||||
functionCall.append(")");
|
||||
}
|
||||
functionCall.append("}");
|
||||
cutPasteFunction.setText(functionCall.toString());
|
||||
GuiUtils.copyTextToClipboard(cutPasteFunction.getText());
|
||||
CompoundVariable function = new CompoundVariable(functionCall.toString());
|
||||
try {
|
||||
resultTextArea.setText(function.execute().trim());
|
||||
} catch(Exception ex) {
|
||||
log.error("Error calling function {}", functionCall.toString(), ex);
|
||||
resultTextArea.setText(ex.getMessage() + ", \nstacktrace:\n "+
|
||||
ExceptionUtils.getStackTrace(ex));
|
||||
resultTextArea.setCaretPosition(0);
|
||||
}
|
||||
return functionCall.toString();
|
||||
}
|
||||
|
||||
private class HelpListener implements ActionListener {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.jmeter.functions.gui;
|
||||
|
||||
import java.awt.event.ActionEvent
|
||||
|
||||
import org.apache.jmeter.config.Argument
|
||||
import org.apache.jmeter.config.Arguments
|
||||
import org.apache.jmeter.junit.spock.JMeterSpec
|
||||
import org.apache.jorphan.gui.GuiUtils
|
||||
|
||||
import spock.lang.IgnoreIf
|
||||
import spock.lang.Unroll
|
||||
|
||||
@Unroll
|
||||
class FunctionHelperSpec extends JMeterSpec {
|
||||
|
||||
@IgnoreIf({ Boolean.valueOf(System.properties['java.awt.headless']) })
|
||||
def "construct correct call string for parameters #parameters"() {
|
||||
setup:
|
||||
def functionHelper = new FunctionHelper()
|
||||
when:
|
||||
def args = new Arguments()
|
||||
args.setArguments(parameters.collect { new Argument("dummy${it}", it)})
|
||||
then:
|
||||
functionHelper.buildFunctionCallString(functionName, args).toString() == combined
|
||||
where:
|
||||
functionName | parameters | combined
|
||||
"fname" | [] | "\${fname}"
|
||||
"fname" | ["a"] | "\${fname(a)}"
|
||||
"fname" | ["a,b"] | "\${fname(a\\,b)}"
|
||||
"fname" | ["a,b,c"] | "\${fname(a\\,b\\,c)}"
|
||||
"fname" | ["a", "b"] | "\${fname(a,b)}"
|
||||
"fname" | ["a,b", "c"] | "\${fname(a\\,b,c)}"
|
||||
}
|
||||
}
|
||||
|
|
@ -237,6 +237,7 @@ this behaviour, set <code>httpclient.reset_state_on_thread_group_iteration=false
|
|||
<li><bug>62397</bug>Don't break lines at commata when using JSON Path Tester</li>
|
||||
<li><bug>62281</bug>Prevent NPE in MapProperty. Patch by belugabehr (dam6923 at gmail.com)</li>
|
||||
<li><bug>62457</bug>In usermanual, the UUID Function's example is wrong. Contributed by helppass (onegaicimasu at hotmail.com)</li>
|
||||
<li><bug>62478</bug>Escape commata in parameters when constructing function strings in the GUI function helper. Reported by blue414 (blue414 at 163.com)</li>
|
||||
</ul>
|
||||
|
||||
<!-- =================== Thanks =================== -->
|
||||
|
|
@ -262,6 +263,7 @@ this behaviour, set <code>httpclient.reset_state_on_thread_group_iteration=false
|
|||
<li>belugabehr (dam6923 at gmail.com)</li>
|
||||
<li>Giancarlo Romeo (giancarloromeo at gmail.com)</li>
|
||||
<li>helppass (onegaicimasu at hotmail.com)</li>
|
||||
<li>blue414 (blue414 at 163.com)</li>
|
||||
</ul>
|
||||
<p>We also thank bug reporters who helped us improve JMeter.</p>
|
||||
<p>
|
||||
|
|
|
|||
Loading…
Reference in New Issue