View | Details | Raw Unified | Return to bug 63099
Collapse All | Expand All

(-)src/core/org/apache/jmeter/functions/gui/FunctionHelper.java (-1 / +39 lines)
Lines 22-27 Link Here
22
import java.awt.FlowLayout;
22
import java.awt.FlowLayout;
23
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionEvent;
24
import java.awt.event.ActionListener;
24
import java.awt.event.ActionListener;
25
import java.io.IOException;
26
import java.io.Reader;
27
import java.io.StringReader;
25
import java.util.Arrays;
28
import java.util.Arrays;
26
import java.util.List;
29
import java.util.List;
27
30
Lines 251-257 Link Here
251
                if (!first) {
254
                if (!first) {
252
                    functionCall.append(",");
255
                    functionCall.append(",");
253
                }
256
                }
254
                functionCall.append(arg.getValue().replaceAll(",", "\\\\,"));
257
                functionCall.append(escapeCommata(arg.getValue()));
255
                first = false;
258
                first = false;
256
            }
259
            }
257
            functionCall.append(")");
260
            functionCall.append(")");
Lines 260-265 Link Here
260
        return functionCall.toString();
263
        return functionCall.toString();
261
    }
264
    }
262
265
266
    private static final char ANY_NORMAL_CHAR = ' ';
267
268
    /**
269
     * Escape commata that are in the argument but "outside" of variable replacement structures.
270
     *
271
     * @param arg string that should be escaped
272
     * @return escaped string
273
     */
274
    private String escapeCommata(String arg) {
275
        int level = 0;
276
        StringBuilder result = new StringBuilder(arg.length());
277
        try (Reader r = new StringReader(arg)) {
278
            int c;
279
            char lastChar = ANY_NORMAL_CHAR;
280
            while ((c = r.read()) != -1) {
281
                char nextChar = (char) c;
282
                if (lastChar == '\\') {
283
                    // do nothing
284
                } else if (lastChar == '$' && nextChar == '{') {
285
                    level++;
286
                } else if (nextChar == '}') {
287
                    level--;
288
                } else if (nextChar == ',' && level == 0) {
289
                    result.append('\\');
290
                }
291
                lastChar = nextChar;
292
                result.append(nextChar);
293
            }
294
        } catch (IOException e) {
295
            log.warn("Can't escape commata in input string: {}", arg, e);
296
            return arg;
297
        }
298
        return result.toString();
299
    }
300
263
    private class HelpListener implements ActionListener {
301
    private class HelpListener implements ActionListener {
264
        @Override
302
        @Override
265
        public void actionPerformed(ActionEvent e) {
303
        public void actionPerformed(ActionEvent e) {
(-)test/src/org/apache/jmeter/functions/gui/FunctionHelperSpec.groovy (+2 lines)
Lines 47-52 Link Here
47
          "fname"      | ["a,b,c"]     | "\${fname(a\\,b\\,c)}"
47
          "fname"      | ["a,b,c"]     | "\${fname(a\\,b\\,c)}"
48
          "fname"      | ["a", "b"]    | "\${fname(a,b)}"
48
          "fname"      | ["a", "b"]    | "\${fname(a,b)}"
49
          "fname"      | ["a,b", "c"]  | "\${fname(a\\,b,c)}"
49
          "fname"      | ["a,b", "c"]  | "\${fname(a\\,b,c)}"
50
          "fname"      | ["\${f(a,b)},c,\${g(d,e)}","h"]   | "\${fname(\${f(a,b)}\\,c\\,\${g(d,e)},h)}"
51
          "fname"      | ["a,\${f(b,\${g(c,d)},e)},f","h"] | "\${fname(a\\,\${f(b,\${g(c,d)},e)}\\,f,h)}"
50
    }
52
    }
51
}
53
}
52
54

Return to bug 63099