Bug 63064 - If Controller evaluates to "False" if expression contains empty line
Summary: If Controller evaluates to "False" if expression contains empty line
Status: RESOLVED FIXED
Alias: None
Product: JMeter
Classification: Unclassified
Component: HTTP (show other bugs)
Version: 5.0
Hardware: PC All
: P2 normal (vote)
Target Milestone: JMETER_5.1
Assignee: JMeter issues mailing list
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2019-01-07 13:56 UTC by Dirk Ronsmans
Modified: 2019-01-08 17:33 UTC (History)
1 user (show)



Attachments
trim expression before evaluation (1.87 KB, patch)
2019-01-07 19:54 UTC, Felix Schumacher
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Ronsmans 2019-01-07 13:56:05 UTC
When creating an expression in an If Controller the expression is being evaluated to false when the last line is an empty one.

Tested with "Interpret condition as variable expression" checked.

e.g.
1. ${__jexl3(${blnChangeRadius} == 1)}

Evaluates to true if blnChangeRadius == 1

1. ${__jexl3(${blnChangeRadius} == 1)}
2. 

Evaluates to false when blnChangeRadius == 1

blnChangeRadius in my case was just a random generated number (min:0 max:1)
Comment 1 Felix Schumacher 2019-01-07 19:54:15 UTC
Created attachment 36368 [details]
trim expression before evaluation

The attached patch fixes the reported behavior. The evaluated expression was "true\n" which got compared to "true" which resulted in false.

I haven't committed the patch yet, as I wanted to add a test case so that we would not stumble upon this bug again, but it seems that the expression (condition) is not evaluated at all with my setup. Is anyone willing to tell me, what is missing there?
Comment 2 Philippe Mouawad 2019-01-07 21:04:52 UTC
(In reply to Felix Schumacher from comment #1)
> Created attachment 36368 [details]
> trim expression before evaluation
> 
> The attached patch fixes the reported behavior. The evaluated expression was
> "true\n" which got compared to "true" which resulted in false.
> 
> I haven't committed the patch yet, as I wanted to add a test case so that we
> would not stumble upon this bug again, but it seems that the expression
> (condition) is not evaluated at all with my setup. Is anyone willing to tell
> me, what is missing there?

You need to call ValueReplacer :
        JMeterContextService.getContext().setVariables(vars);
        JMeterContextService.getContext().setSamplingStarted(true);
        ValueReplacer replacer = new ValueReplacer();
        replacer.setUserDefinedVariables(testPlan.getUserDefinedVariables());


Still it doesn't work with function and variable.
Something to be investigated I guess.
Comment 3 Felix Schumacher 2019-01-08 17:33:52 UTC
Thanks for the report. This will be fixed in version 5.1. It would be nice, if you could test the next nightly and report, if it works for you.

@pmouawad I implemented a simpler version of the test, that didn't need any variable expansion at all.

Date: Tue Jan  8 17:30:48 2019
New Revision: 1850776

URL: http://svn.apache.org/viewvc?rev=1850776&view=rev
Log:
Ignore spaces at the end and beginning of expressions used in IfController

Bugzilla Id: 63064

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java
    jmeter/trunk/test/src/org/apache/jmeter/control/TestIfController.java
    jmeter/trunk/xdocs/changes.xml