Index: lib/filterClasses.js |
=================================================================== |
--- a/lib/filterClasses.js |
+++ b/lib/filterClasses.js |
@@ -683,21 +683,24 @@ |
* letters |
* @param {string} [domains] |
* Domains that the filter is restricted to, e.g. "foo.com|bar.com|~baz.com" |
* @param {boolean} [thirdParty] |
* Defines whether the filter should apply to third-party or first-party |
* content only |
* @param {string} [sitekeys] |
* Public keys of websites that this filter should apply to |
+ * @param {?string} [rewrite] |
+ * The (optional) rule specifying how to rewrite the URL. See |
+ * BlockingFilter.prototype.rewrite. |
* @constructor |
* @augments ActiveFilter |
*/ |
function RegExpFilter(text, regexpSource, contentType, matchCase, domains, |
- thirdParty, sitekeys) |
+ thirdParty, sitekeys, rewrite) |
{ |
ActiveFilter.call(this, text, domains); |
if (contentType != null) |
this.contentType = contentType; |
if (matchCase) |
this.matchCase = matchCase; |
if (thirdParty != null) |
@@ -712,16 +715,22 @@ |
// The filter is a regular expression - convert it immediately to |
// catch syntax errors |
let regexp = new RegExp(regexpSource.substr(1, regexpSource.length - 2), |
this.matchCase ? "" : "i"); |
Object.defineProperty(this, "regexp", {value: regexp}); |
} |
else |
{ |
+ // Patterns like /foo/bar/* exist so that they are not treated as regular |
+ // expressions. We drop any superfluous wildcards here so our optimizations |
+ // can kick in. |
+ if (rewrite == null) |
+ regexpSource = regexpSource.replace(/^\*+/, "").replace(/\*+$/, ""); |
+ |
if (!this.matchCase && isLiteralPattern(regexpSource)) |
regexpSource = regexpSource.toLowerCase(); |
// No need to convert this filter to regular expression yet, do it on demand |
this.pattern = regexpSource; |
} |
} |
exports.RegExpFilter = RegExpFilter; |
@@ -1065,17 +1074,17 @@ |
* BlockingFilter.prototype.rewrite. |
* @constructor |
* @augments RegExpFilter |
*/ |
function BlockingFilter(text, regexpSource, contentType, matchCase, domains, |
thirdParty, sitekeys, collapse, csp, rewrite) |
{ |
RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
- thirdParty, sitekeys); |
+ thirdParty, sitekeys, rewrite); |
if (collapse != null) |
this.collapse = collapse; |
if (csp != null) |
this.csp = csp; |
if (rewrite != null) |