Browse Source

use jsonQuoteRegex instead of Pattern.quote

tags/2.0.1
Jonathan Cobb 5 years ago
parent
commit
cab1859a59
2 changed files with 7 additions and 6 deletions
  1. +5
    -4
      src/main/java/bubble/abp/spec/BlockSpecTarget.java
  2. +2
    -2
      src/main/java/bubble/abp/spec/selector/AbpProperty.java

+ 5
- 4
src/main/java/bubble/abp/spec/BlockSpecTarget.java View File

@@ -13,6 +13,7 @@ import java.util.regex.Pattern;

import static org.cobbzilla.util.daemon.ZillaRuntime.empty;
import static org.cobbzilla.util.http.HttpSchemes.stripScheme;
import static org.cobbzilla.util.json.JsonUtil.jsonQuoteRegex;

@NoArgsConstructor @Accessors(chain=true) @EqualsAndHashCode(of={"domainRegex", "regex"})
public class BlockSpecTarget {
@@ -59,7 +60,7 @@ public class BlockSpecTarget {
} else if (data.startsWith("|") && data.endsWith("|")) {
// exact match
final String verbatimMatch = stripScheme(data.substring(1, data.length() - 1));
regex = "^" + Pattern.quote(verbatimMatch) + "$";
regex = "^" + jsonQuoteRegex(verbatimMatch) + "$";

} else if (data.startsWith("/")) {
// path match, possibly regex
@@ -72,14 +73,14 @@ public class BlockSpecTarget {
} else if (data.contains("*")) {
regex = parseWildcardMatch(data);
} else {
regex = "^" + Pattern.quote(data) + ".*";
regex = "^" + jsonQuoteRegex(data) + ".*";
}

} else {
if (data.contains("*")) {
regex = parseWildcardMatch(data);
} else {
regex = "^" + Pattern.quote(data) + ".*";
regex = "^" + jsonQuoteRegex(data) + ".*";
}
}
return new BlockSpecTarget().setDomainRegex(domainRegex).setRegex(regex);
@@ -96,7 +97,7 @@ public class BlockSpecTarget {
}

private static String matchDomainOrAnySubdomains(String domain) {
return ".*?"+Pattern.quote(domain)+"$";
return ".*?"+jsonQuoteRegex(domain)+"$";
}

}

+ 2
- 2
src/main/java/bubble/abp/spec/selector/AbpProperty.java View File

@@ -4,9 +4,9 @@ import lombok.*;
import lombok.experimental.Accessors;

import java.util.StringTokenizer;
import java.util.regex.Pattern;

import static bubble.abp.spec.selector.SelectorParseError.parseError;
import static org.cobbzilla.util.json.JsonUtil.jsonQuoteRegex;

@NoArgsConstructor @Accessors(chain=true)
@EqualsAndHashCode @ToString
@@ -30,7 +30,7 @@ public class AbpProperty {
if (tok.equals("*")) {
regex.append(".+?");
} else {
regex.append(Pattern.quote(tok));
regex.append(jsonQuoteRegex(tok));
}
}
return new AbpProperty()


Loading…
Cancel
Save