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

Unified Diff: lib/filterClasses.js

Issue 29800595: Issue 6735 - Store domains in lower case (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Disallow missing values in domain, sitekey, and rewrite Created June 8, 2018, 2:16 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 | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | 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
@@ -382,38 +382,38 @@
/**
* Separator character used in domainSource property, must be
* overridden by subclasses
* @type {string}
*/
domainSeparator: null,
/**
- * Determines whether domainSource is already upper-case,
+ * Determines whether domainSource is already lower-case,
* can be overridden by subclasses.
* @type {boolean}
*/
- domainSourceIsUpperCase: false,
+ domainSourceIsLowerCase: false,
/**
* Map containing domains that this filter should match on/not match
* on or null if the filter should match on all domains
* @type {?Map.<string,boolean>}
*/
get domains()
{
let domains = null;
if (this.domainSource)
{
let source = this.domainSource;
- if (!this.domainSourceIsUpperCase)
+ if (!this.domainSourceIsLowerCase)
{
- // RegExpFilter already have uppercase domains
- source = source.toUpperCase();
+ // RegExpFilter already have lowercase domains
+ source = source.toLowerCase();
}
let list = source.split(this.domainSeparator);
if (list.length == 1 && list[0][0] != "~")
{
// Fast track for the common one-domain scenario
domains = new Map([["", false], [list[0], true]]);
}
else
@@ -480,17 +480,17 @@
if (!this.domains)
return true;
// If the document has no host name, match only if the filter
// isn't restricted to specific domains
if (!docDomain)
return this.domains.get("");
- docDomain = docDomain.replace(/\.+$/, "").toUpperCase();
+ docDomain = docDomain.replace(/\.+$/, "").toLowerCase();
while (true)
{
let isDomainIncluded = this.domains.get(docDomain);
if (typeof isDomainIncluded != "undefined")
return isDomainIncluded;
let nextDot = docDomain.indexOf(".");
@@ -506,17 +506,17 @@
* @param {string} docDomain
* @return {boolean}
*/
isActiveOnlyOnDomain(docDomain)
{
if (!docDomain || !this.domains || this.domains.get(""))
return false;
- docDomain = docDomain.replace(/\.+$/, "").toUpperCase();
+ docDomain = docDomain.replace(/\.+$/, "").toLowerCase();
for (let [domain, isIncluded] of this.domains)
{
if (isIncluded && domain != docDomain)
{
if (domain.length <= docDomain.length)
return false;
@@ -607,19 +607,19 @@
// No need to convert this filter to regular expression yet, do it on demand
this.regexpSource = regexpSource;
}
}
exports.RegExpFilter = RegExpFilter;
RegExpFilter.prototype = extend(ActiveFilter, {
/**
- * @see ActiveFilter.domainSourceIsUpperCase
+ * @see ActiveFilter.domainSourceIsLowerCase
*/
- domainSourceIsUpperCase: true,
+ domainSourceIsLowerCase: true,
/**
* Number of filters contained, will always be 1 (required to
* optimize Matcher).
* @type {number}
*/
length: 1,
@@ -750,50 +750,70 @@
{
let value = null;
let separatorIndex = option.indexOf("=");
if (separatorIndex >= 0)
{
value = option.substr(separatorIndex + 1);
option = option.substr(0, separatorIndex);
}
- option = option.replace(/-/, "_").toUpperCase();
- if (option in RegExpFilter.typeMap)
- {
- contentType |= RegExpFilter.typeMap[option];
+
+ let inverse = option[0] == "~";
+ if (inverse)
+ option = option.substr(1);
- if (option == "CSP" && value)
- csp = value;
- }
- else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap)
+ let type = RegExpFilter.typeMap[option.replace(/-/, "_").toUpperCase()];
+ if (type)
{
- if (contentType == null)
- ({contentType} = RegExpFilter.prototype);
- contentType &= ~RegExpFilter.typeMap[option.substr(1)];
+ if (inverse)
+ {
+ if (contentType == null)
+ ({contentType} = RegExpFilter.prototype);
+ contentType &= ~type;
+ }
+ else
+ {
+ contentType |= type;
+
+ if (type == RegExpFilter.typeMap.CSP && value)
Manish Jethani 2018/06/08 14:21:14 By the way in the case of csp we quietly ignore th
kzar 2018/06/15 10:44:03 Yea, agreed. By the way Rosie is reimplementing th
+ csp = value;
+ }
}
- else if (option == "MATCH_CASE")
- matchCase = true;
- else if (option == "~MATCH_CASE")
- matchCase = false;
- else if (option == "DOMAIN" && value)
- domains = value.toUpperCase();
- else if (option == "THIRD_PARTY")
- thirdParty = true;
- else if (option == "~THIRD_PARTY")
- thirdParty = false;
- else if (option == "COLLAPSE")
- collapse = true;
- else if (option == "~COLLAPSE")
- collapse = false;
- else if (option == "SITEKEY" && value)
- sitekeys = value.toUpperCase();
- else if (option == "REWRITE" && value)
- rewrite = value;
else
- return new InvalidFilter(origText, "filter_unknown_option");
+ {
+ switch (option.toLowerCase())
+ {
+ case "match-case":
+ matchCase = !inverse;
+ break;
+ case "domain":
+ if (!value)
+ return new InvalidFilter(origText, "filter_unknown_option");
+ domains = value.toLowerCase();
+ break;
+ case "third-party":
+ thirdParty = !inverse;
+ break;
+ case "collapse":
+ collapse = !inverse;
+ break;
+ case "sitekey":
+ if (!value)
Manish Jethani 2018/06/08 14:19:42 There's a bit of code repetition here but I'm OK w
kzar 2018/06/15 10:44:03 Yea, I think it's fine.
+ return new InvalidFilter(origText, "filter_unknown_option");
+ sitekeys = value.toUpperCase();
+ break;
+ case "rewrite":
+ if (!value)
Manish Jethani 2018/06/08 14:19:42 Note that this will get updated for the rewrite op
+ return new InvalidFilter(origText, "filter_unknown_option");
+ rewrite = value;
+ break;
+ default:
+ return new InvalidFilter(origText, "filter_unknown_option");
+ }
+ }
}
}
// For security reasons, never match $rewrite filters
// against requests that might load any code to be executed.
if (rewrite != null)
{
if (contentType == null)
« no previous file with comments | « lib/elemHide.js ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld