apache / apache/jmeter

Question mark needs to be escaped multiple times in JSR223 Processors

Open
#5,515 1 comment 0 reactions 0 assignees View on GitHub
need info os: All P2
Dominant language
Java
Stars
9.5k
Forks
2.3k
Avg merge
1d 22h
Merged PRs (30d)
5

Description

**gergely.lukacsy** ([Bug 65205](https://bz.apache.org/bugzilla//show_bug.cgi?id=65205&redirect=false)):
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.