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

Unified Diff: lib/filterClasses.js

Issue 11111045: Mark filters with unknown options as invalid (Closed)
Patch Set: Created July 18, 2013, 7:34 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
@@ -603,28 +603,32 @@ RegExpFilter.fromText = function(text)
else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap)
{
if (contentType == null)
contentType = RegExpFilter.prototype.contentType;
contentType &= ~RegExpFilter.typeMap[option.substr(1)];
}
else if (option == "MATCH_CASE")
matchCase = true;
+ else if (option == "~MATCH_CASE")
+ matchCase = false;
else if (option == "DOMAIN" && typeof value != "undefined")
domains = value;
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" && typeof value != "undefined")
siteKeys = value.split(/\|/);
+ else
+ return new InvalidFilter(origText, "Unknown option " + option.toLowerCase());
}
}
if (!blocking && (contentType == null || (contentType & RegExpFilter.typeMap.DOCUMENT)) &&
(!options || options.indexOf("DOCUMENT") < 0) && !/^\|?[\w\-]+:/.test(text))
{
// Exception filters shouldn't apply to pages by default unless they start with a protocol name
if (contentType == null)
@@ -638,17 +642,17 @@ RegExpFilter.fromText = function(text)
{
if (blocking)
return new BlockingFilter(origText, text, contentType, matchCase, domains, thirdParty, collapse);
else
return new WhitelistFilter(origText, text, contentType, matchCase, domains, thirdParty, siteKeys);
}
catch (e)
{
- return new InvalidFilter(text, e);
+ return new InvalidFilter(origText, e);
}
}
/**
* Maps type strings like "SCRIPT" or "OBJECT" to bit masks
*/
RegExpFilter.typeMap = {
OTHER: 1,
@@ -664,22 +668,21 @@ RegExpFilter.typeMap = {
OBJECT_SUBREQUEST: 4096,
DTD: 1,
MEDIA: 16384,
FONT: 32768,
BACKGROUND: 4, // Backwards compat, same as IMAGE
POPUP: 0x10000000,
- DONOTTRACK: 0x20000000,
ELEMHIDE: 0x40000000
};
-// ELEMHIDE, DONOTTRACK, POPUP option shouldn't be there by default
-RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.ELEMHIDE | RegExpFilter.typeMap.DONOTTRACK | RegExpFilter.typeMap.POPUP);
+// ELEMHIDE, POPUP option shouldn't be there by default
+RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP);
/**
* Class for blocking filters
* @param {String} text see Filter()
* @param {String} regexpSource see RegExpFilter()
* @param {Number} contentType see RegExpFilter()
* @param {Boolean} matchCase see RegExpFilter()
* @param {String} domains see RegExpFilter()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld