Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/filterClasses.js

Issue 29978576: Issue 7208 - Drop superfluous wildcards before processing pattern (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Jan. 10, 2019, 10:43 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
Manish Jethani 2019/01/10 22:52:22 I don't like this, but unfortunately the superclas
- 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 superflous 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)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld