Am 17.01.19 um 14:20 schrieb sebb:
On Thu, 17 Jan 2019 at 12:17, Felix Schumacher
<felix.schumac...@internetallee.de> wrote:

Am 15.01.19 um 16:51 schrieb Philippe Mouawad:
Hello,
We have a bug report considered as regression on jmeter-fr google group :
- https://groups.google.com/forum/#!topic/jmeter-fr/es1ikcAxsDE

In summary previously when using function composition in Function Helper
Dialog:
Instead of:
${__urlencode(${__time(dd/MM/yyyy,NEWVAR)})}

The helper generates (notice '\,' instead of ','):
${__urlencode(${__time(dd/MM/yyyy\,NEWVAR)})}

Issue is due to another bug fix 62478:
- http://svn.apache.org/viewvc?rev=1834192&view=rev

Any idea how we should fix this ?
So the problem is that ${...} values are getting their commata escaped?

Maybe we could try to split the values with that in mind?
That should work, provided that the user has used the GUI to escape
the nested function call.
[It's not possible to decide how to escape a nested call, as its
parameter boundaries are not known. Consider a time format containing
a comma.]

The code will have to ignore anything enclosed in ${...}, but still
escape commas elsewhere in a parameter.
However it will require more than a simple split, as the function
calls may be nested more than 1 deep.
I have attached a "simple" patch to make the escaping a bit smarter, but it will still fail at a lot of corner cases, for example nested functions.

Alternatively, don't try to be too clever.
Instead of escaping commas, show a warning if a parameter contains a comma.

That may be a good idea, at least when a comma and "${" is found in the input argument.

Felix


Regards,

   Felix

Thanks
Regards
Philippe M.
https://leanpub.com/master-jmeter-from-load-test-to-devops

Index: src/core/org/apache/jmeter/functions/gui/FunctionHelper.java
===================================================================
--- src/core/org/apache/jmeter/functions/gui/FunctionHelper.java	(Revision 1851572)
+++ src/core/org/apache/jmeter/functions/gui/FunctionHelper.java	(Arbeitskopie)
@@ -24,6 +24,8 @@
 import java.awt.event.ActionListener;
 import java.util.Arrays;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.swing.AbstractAction;
 import javax.swing.Action;
@@ -251,7 +253,7 @@
                 if (!first) {
                     functionCall.append(",");
                 }
-                functionCall.append(arg.getValue().replaceAll(",", "\\\\,"));
+                functionCall.append(escapeArgument(arg.getValue()));
                 first = false;
             }
             functionCall.append(")");
@@ -260,6 +262,20 @@
         return functionCall.toString();
     }
 
+    private String escapeArgument(String arg) {
+        Pattern functionFinder = Pattern.compile("(\\$\\{.*?\\})");
+        Matcher matcher = functionFinder.matcher(arg);
+        StringBuilder result = new StringBuilder();
+        int pos = 0;
+        while (matcher.find()) {
+            result.append(arg.substring(pos, matcher.start()).replaceAll(",", "\\\\,"));
+            result.append(matcher.group(1));
+            pos = matcher.end();
+        }
+        result.append(arg.substring(pos).replaceAll(",", "\\\\,"));
+        return result.toString();
+    }
+
     private class HelpListener implements ActionListener {
         @Override
         public void actionPerformed(ActionEvent e) {
Index: test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy
===================================================================
--- test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy	(Revision 1851572)
+++ test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy	(Arbeitskopie)
@@ -47,6 +47,10 @@
           "fname"      | ["a,b,c"]     | "\${fname(a\\,b\\,c)}"
           "fname"      | ["a", "b"]    | "\${fname(a,b)}"
           "fname"      | ["a,b", "c"]  | "\${fname(a\\,b,c)}"
+          "fname"      | ["a", "\${f2(x,y)}", "b"] | "\${fname(a,\${f2(x,y)},b)}"
+          "fname"      | ["a,\${f2(x,y)}", "b"] | "\${fname(a\\,\${f2(x,y)},b)}"
+          "fname"      | ["a,\${f2(x,y)},b,\${f3(i,j)}", "c"] | "\${fname(a\\,\${f2(x,y)}\\,b\\,\${f3(i,j)},c)}"
+          "fname"      | ["\${f2(x,y)}", "a,b", "\${f3(i,j)}", "c,d"] | "\${fname(\${f2(x,y)},a\\,b,\${f3(i,j)},c\\,d)}"
     }
 }
 

Reply via email to