Bug 64198 - Spaces at the end of ${...}
Summary: Spaces at the end of ${...}
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 5.2
Hardware: All All
: P2 minor (vote)
Target Milestone: JMETER_5.3.0
Assignee: JMeter issues mailing list
Keywords: FixedInTrunk, PatchAvailable
Depends on:
Reported: 2020-03-04 17:29 UTC by Felix Schumacher
Modified: 2020-03-07 13:50 UTC (History)
0 users

Skip spaces before a matching closing brace (1.44 KB, patch)
2020-03-04 21:13 UTC, Felix Schumacher
Details | Diff
Allow spaces around function expressions (4.68 KB, patch)
2020-03-05 20:37 UTC, Felix Schumacher
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Felix Schumacher 2020-03-04 17:29:01 UTC
When JMeter evaluates an expression like "${__groovy(true) }" it will throw an exception like:

rg.apache.jmeter.functions.InvalidVariableException: Expected } after __groovy function call in ${__groovy(true) }
	at org.apache.jmeter.engine.util.FunctionParser.makeFunction(FunctionParser.java:135) ~[ApacheJMeter_core.jar:5.3-SNAPSHOT]
	at org.apache.jmeter.engine.util.FunctionParser.compileString(FunctionParser.java:78) ~[ApacheJMeter_core.jar:5.3-SNAPSHOT]
	at org.apache.jmeter.engine.util.CompoundVariable.setParameters(CompoundVariable.java:180) ~[ApacheJMeter_core.jar:5.3-SNAPSHOT]
	at org.apache.jmeter.engine.util.ReplaceStringWithFunctions.transformValue(ReplaceStringWithFunctions.java:42) ~[ApacheJMeter_core.jar:5.3-SNAPSHOT]
	at org.apache.jmeter.engine.util.ValueReplacer.replaceValues(ValueReplacer.java:169) ~[ApacheJMeter_core.jar:5.3-SNAPSHOT]
	at org.apache.jmeter.engine.util.ValueReplacer.replaceValues(ValueReplacer.java:79) ~[ApacheJMeter_core.jar:5.3-SNAPSHOT]
	at org.apache.jmeter.engine.PreCompiler.addNode(PreCompiler.java:88) [ApacheJMeter_core.jar:5.3-SNAPSHOT]
	at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:993) [jorphan.jar:5.3-SNAPSHOT]
	at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:994) [jorphan.jar:5.3-SNAPSHOT]
	at org.apache.jorphan.collections.HashTree.traverse(HashTree.java:976) [jorphan.jar:5.3-SNAPSHOT]
	at org.apache.jmeter.engine.StandardJMeterEngine.run(StandardJMeterEngine.java:361) [ApacheJMeter_core.jar:5.3-SNAPSHOT]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_201]

If the expression is used without the space before the closing brace like "${__groovy(true)}" it works as expected.

I think that we should be more forgiving here and ignore spaces before the closing brace.
Comment 1 Felix Schumacher 2020-03-04 21:13:22 UTC
Created attachment 37063 [details]
Skip spaces before a matching closing brace
Comment 2 Felix Schumacher 2020-03-05 20:37:43 UTC
Created attachment 37065 [details]
Allow spaces around function expressions
Comment 3 Felix Schumacher 2020-03-07 13:50:25 UTC
commit 89ed2ef64bea7a082171ea8dcc1c9cb1a2e302bf
AuthorDate: Thu Mar 5 21:35:20 2020 +0100

    Allow spaces in ${...} expressions around function calls.
    With this change it is possible to write
     ${ __P(something, 1) }
    where such an expression would previously have resulted in an error.
    Bugzilla Id: 64198
 .../apache/jmeter/engine/util/FunctionParser.java  | 14 ++++-
 .../jmeter/engine/util/FunctionParserSpec.groovy   | 62 ++++++++++++++++++++++
 xdocs/changes.xml                                  |  1 +
 3 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/src/core/src/main/java/org/apache/jmeter/engine
Comment 4 The ASF infrastructure team 2022-09-24 20:38:19 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/5253