Skip to content
Permalink
Browse files
Add a switch to decide which regex engine should be used
  • Loading branch information
FSchumacher committed Mar 5, 2022
1 parent 283e3b3 commit e74cb153d2d45d5007365a6eb9c59b5f1fc44967
Showing 1 changed file with 22 additions and 3 deletions.
@@ -18,6 +18,7 @@
package org.apache.jmeter.protocol.http.config;

import java.io.Serializable;
import java.util.regex.Matcher;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HeaderElement;
@@ -54,6 +55,8 @@ public class MultipartUrlConfig implements Serializable {

private static final Logger log = LoggerFactory.getLogger(MultipartUrlConfig.class);

private static boolean useJavaRegex = JMeterUtils.getPropDefault("jmeter.use_java_regex", false);

/**
* HTTPFileArgs list to be uploaded with http request.
*/
@@ -183,6 +186,24 @@ private static String getParameterValue(HeaderElement element, String name, Stri

private static String getHeaderValue(String headerName, String multiPart) {
String regularExpression = headerName + "\\s*:\\s*(.*)$"; //$NON-NLS-1$
if (useJavaRegex) {
return getHeaderValueWithJavaRegex(headerName, multiPart, regularExpression);
}
return getHeaderValueWithOroRegex(headerName, multiPart, regularExpression);
}

private static String getHeaderValueWithJavaRegex(String headerName, String multiPart, String regularExpression) {
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regularExpression,
java.util.regex.Pattern.CASE_INSENSITIVE
| java.util.regex.Pattern.MULTILINE);
Matcher matcher = pattern.matcher(multiPart);
if (matcher.find()) {
return matcher.group(1).trim();
}
return null;
}

private static String getHeaderValueWithOroRegex(String headerName, String multiPart, String regularExpression) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
Pattern pattern = JMeterUtils.getPattern(regularExpression,
Perl5Compiler.READ_ONLY_MASK
@@ -191,8 +212,6 @@ private static String getHeaderValue(String headerName, String multiPart) {
if(localMatcher.contains(multiPart, pattern)) {
return localMatcher.getMatch().group(1).trim();
}
else {
return null;
}
return null;
}
}

0 comments on commit e74cb15

Please sign in to comment.