You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2018/06/23 12:07:10 UTC
svn commit: r1834192 - in /jmeter/trunk:
src/core/org/apache/jmeter/functions/gui/FunctionHelper.java
test/src/org/apache/jmeter/functions/gui/
test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy
xdocs/changes.xml
Author: fschumacher
Date: Sat Jun 23 12:07:10 2018
New Revision: 1834192
URL: http://svn.apache.org/viewvc?rev=1834192&view=rev
Log:
Escape commata in parameters when constructing function strings in the GUI function helper.
Bugzilla Id: 62478
Added:
jmeter/trunk/test/src/org/apache/jmeter/functions/gui/
jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy (with props)
Modified:
jmeter/trunk/src/core/org/apache/jmeter/functions/gui/FunctionHelper.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/core/org/apache/jmeter/functions/gui/FunctionHelper.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/functions/gui/FunctionHelper.java?rev=1834192&r1=1834191&r2=1834192&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/functions/gui/FunctionHelper.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/functions/gui/FunctionHelper.java Sat Jun 23 12:07:10 2018
@@ -175,9 +175,25 @@ public class FunctionHelper extends JDia
@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 JDia
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 {
Added: jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy?rev=1834192&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy Sat Jun 23 12:07:10 2018
@@ -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)}"
+ }
+}
\ No newline at end of file
Propchange: jmeter/trunk/test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1834192&r1=1834191&r2=1834192&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sat Jun 23 12:07:10 2018
@@ -237,6 +237,7 @@ this behaviour, set <code>httpclient.res
<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.res
<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>