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

Unified Diff: lib/filterClasses.js

Issue 30021563: Issue 7321 - Lower-case non-literal patterns for case-insensitive matching (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created March 1, 2019, 10:59 a.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
@@ -719,37 +719,36 @@
this.thirdParty = thirdParty;
if (sitekeys != null)
this.sitekeySource = sitekeys;
if (rewrite != null)
this.rewrite = rewrite;
if (resourceName)
this.resourceName = resourceName;
+ if (!this.matchCase)
+ regexpSource = regexpSource.toLowerCase();
+
if (regexpSource.length >= 2 &&
regexpSource[0] == "/" &&
regexpSource[regexpSource.length - 1] == "/")
{
// The filter is a regular expression - convert it immediately to
// catch syntax errors
- let regexp = new RegExp(regexpSource.substring(1, regexpSource.length - 1),
- this.matchCase ? "" : "i");
+ let regexp = new RegExp(regexpSource.substring(1, regexpSource.length - 1));
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 (this.rewrite == null || this.resourceName)
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;
RegExpFilter.prototype = extend(ActiveFilter, {
/**
@@ -776,20 +775,17 @@
* @type {RegExp}
*/
get regexp()
{
let value = null;
let {pattern, rewrite, resourceName} = this;
if ((rewrite != null && !resourceName) || !isLiteralPattern(pattern))
- {
- value = new RegExp(filterToRegExp(pattern, rewrite != null),
- this.matchCase ? "" : "i");
- }
+ value = new RegExp(filterToRegExp(pattern, rewrite != null));
Object.defineProperty(this, "regexp", {value});
return value;
},
/**
* Content types the filter applies to, combination of values from
* RegExpFilter.typeMap
* @type {number}
@@ -893,24 +889,24 @@
* @param {string} location The URL to check.
* @param {?string} [lowerCaseLocation] The lower-case version of the URL to
* check, for case-insensitive matching.
* @returns {boolean} <code>true</code> if the URL matches.
* @package
*/
matchesLocation(location, lowerCaseLocation)
{
+ if (!this.matchCase)
+ location = lowerCaseLocation || location.toLowerCase();
+
let {regexp} = this;
if (regexp)
return regexp.test(location);
- if (!this.matchCase)
- location = lowerCaseLocation || location.toLowerCase();
-
let {pattern} = this;
let startsWithDoubleAnchor = pattern[0] == "|" && pattern[1] == "|";
let endsWithSeparator = pattern[pattern.length - 1] == "^";
if (startsWithDoubleAnchor)
pattern = pattern.substr(2);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld