Bug 65205

Summary: Question mark needs to be escaped multiple times in JSR223 Processors
Product: JMeter Reporter: gergely.lukacsy
Component: MainAssignee: JMeter issues mailing list <issues>
Status: NEEDINFO ---    
Severity: normal    
Priority: P2    
Version: 5.4.1   
Target Milestone: JMETER_5.5   
Hardware: PC   
OS: All   

Description gergely.lukacsy 2021-03-26 18:34:46 UTC
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.
Comment 1 Felix Schumacher 2021-04-10 12:23:02 UTC
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://bz.apache.org/bugzilla/show_bug.cgi?id=63255 )