Skip to content
Permalink
Browse files
$ is a special character in Java Regex
Guard it for usage within a Regex
  • Loading branch information
FSchumacher committed Mar 5, 2022
1 parent 8da5aab commit ee0ae7697c6bd015efb541a84cece7c7615840f0
Showing 1 changed file with 2 additions and 1 deletion.
@@ -47,6 +47,7 @@ public class ReplaceFunctionsWithStrings extends AbstractTransformer {
* Functions are wrapped in ${ and }
*/
private static final String FUNCTION_REF_PREFIX = "${"; //$NON-NLS-1$
private static final String FUNCTION_REF_PREFIX_REGEX_SAFE = "\\${"; //$NON-NLS-1$
/**
* Functions are wrapped in ${ and }
*/
@@ -112,7 +113,7 @@ private JMeterProperty transformValueWithJavaRegex(JMeterProperty prop) throws I
if (regexMatch) {
try {
java.util.regex.Pattern pattern = JMeterUtils.compilePattern(constructPattern(value));
input = pattern.matcher(input).replaceAll(FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX);
input = pattern.matcher(input).replaceAll(FUNCTION_REF_PREFIX_REGEX_SAFE + key + FUNCTION_REF_SUFFIX);
} catch (PatternSyntaxException e) {
log.warn("Malformed pattern: {}", value);
}

0 comments on commit ee0ae76

Please sign in to comment.