Commit 1bdffc1e authored by 黄亿华's avatar 黄亿华

Merge pull request !337 from Almark Ming/master

parents 0c3ff3d6 91ed66ec
...@@ -26,12 +26,21 @@ public class RegexSelector implements Selector { ...@@ -26,12 +26,21 @@ public class RegexSelector implements Selector {
if (StringUtils.isBlank(regexStr)) { if (StringUtils.isBlank(regexStr)) {
throw new IllegalArgumentException("regex must not be empty"); throw new IllegalArgumentException("regex must not be empty");
} }
/* Can't detect '\(', '(?:)' so that would result in ArrayIndexOutOfBoundsException
if (!StringUtils.contains(regexStr, "(") && !StringUtils.contains(regexStr, ")")) { if (!StringUtils.contains(regexStr, "(") && !StringUtils.contains(regexStr, ")")) {
regexStr = "(" + regexStr + ")"; regexStr = "(" + regexStr + ")";
} }
if (!StringUtils.contains(regexStr, "(") || !StringUtils.contains(regexStr, ")")) { if (!StringUtils.contains(regexStr, "(") || !StringUtils.contains(regexStr, ")")) {
throw new IllegalArgumentException("regex must have capture group 1"); throw new IllegalArgumentException("regex must have capture group 1");
} }
*/
// Try to fix: Only check if there exists the valid left parenthesis, leave regexp validation for Pattern
if (StringUtils.countMatches(regexStr, "(") - StringUtils.countMatches(regexStr, "\\\\\\(") ==
StringUtils.countMatches(regexStr, "(?:") - StringUtils.countMatches(regexStr, "\\\\\\(?:")) {
regexStr = "(" + regexStr + ")";
}
this.regexStr = regexStr; this.regexStr = regexStr;
try { try {
regex = Pattern.compile(regexStr, Pattern.DOTALL | Pattern.CASE_INSENSITIVE); regex = Pattern.compile(regexStr, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment