apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
8.1k stars 2.06k forks source link

Question mark needs to be escaped multiple times in JSR223 Processors #5515

Open asfimport opened 3 years ago

asfimport commented 3 years ago

gergely.lukacsy (Bug 65205): I suspect there's an issue with the special- and escape characters evaluation in JSR233 processors, it is present in both 5.4.1, 5.2.1 and 5.1.1 versions, and it probably goes back to earlier versions too.

Test environment: Win10 /w Java(TM) SE Runtime Environment (build 1.8.0_261-b12)

Issue/steps to repro: I have a JSR233 PreProcessor that runs a small Groovy script, which basically chops an URL into smaller chunks and stores them in their jmeter variables. When I try to split a string with a question mark delimiter, I get a "java.util.regex.PatternSyntaxException: Dangling meta character" exception:

def tmp = s.split('?') // java.util.regex.PatternSyntaxException: Dangling meta character '?

No problem, it needs to be escaped, like this:

def tmp = s.split('\?')

The version above is a valid groovy code, it compiles and runs in the JDoodle online tester (or any other JDK for that matter) -however-, running the test in jmeter gives this error:

2021-03-26 17:28:08,933 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, Parse user input javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script302.groovy: 13: Unexpected input: '(' @ line 13, column 23. def tmp = s.split('\?') ^

Looks like the second backslash disappeared, suggesting there's some kind of double (un)escaping going in the background. So the solution is to double-double escape the meta-character, the modified line below both compiles and runs in jmeter:

def tmp = s.split('\\?')

I'm not sure if this is intentional, but sweeping trough the documentation and browsing trough countless S:O threads and tutorials yield no evidence about this. It is a pretty confusing behavior, to say the least.

Severity: normal OS: All

asfimport commented 3 years ago

@FSchumacher (migrated from Bugzilla): Can you give us a minimal test plan, that shows this behaviour?

JMeter will behave differently on text input if a $ character is inside that text. (That would mean, you have the same problem as https://github.com/apache/jmeter/issues/5035 )