Bug 65205 - Question mark needs to be escaped multiple times in JSR223 Processors
Summary: Question mark needs to be escaped multiple times in JSR223 Processors
Status: NEEDINFO
Alias: None
Product: JMeter
Classification: Unclassified
Component: Main (show other bugs)
Version: 5.4.1
Hardware: PC All
: P2 normal (vote)
Target Milestone: JMETER_5.5
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-26 18:34 UTC by gergely.lukacsy
Modified: 2021-04-10 12:23 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 )