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

Unified Diff: lib/filterClasses.js

Issue 29356018: Issue 4450 - Prevent ElemHide filters with empty domains (Closed)
Patch Set: Created Oct. 5, 2016, 2:24 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/elemHide.js » ('j') | test/filterClasses.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClasses.js
diff --git a/lib/filterClasses.js b/lib/filterClasses.js
index ebfe551604cf296e582fbd6e7cdeca87bbe66237..27dff31eccaa77d4dda7ed512185f8688208873d 100644
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -22,6 +22,28 @@
let {FilterNotifier} = require("filterNotifier");
let {extend} = require("coreUtils");
+// Helper function used to determine if a filter has any empty domains or not.
+function emptyDomains(domains, separator)
+{
+ let emptySoFar = true;
+ for (let i = 0; i < domains.length; i++)
+ {
+ switch (domains[i])
+ {
+ case separator:
+ if (emptySoFar)
+ return true;
+ emptySoFar = true;
+ break;
+ case "~":
+ break;
+ default:
+ emptySoFar = false;
+ }
+ }
+ return emptySoFar;
+}
+
/**
* Abstract base class for filters
*
@@ -924,6 +946,9 @@ ElemHideBase.fromText = function(text, domain, isException, tagName, attrRules,
return new InvalidFilter(text, "filter_elemhide_nocriteria");
}
+ if (domain && emptyDomains(domain, ElemHideBase.prototype.domainSeparator))
Wladimir Palant 2016/10/06 08:06:14 Why have this function rather than /(^|,)~?(,|$)/.
kzar 2016/10/06 08:53:55 Done.
+ return new InvalidFilter(text, "filter_empty_domain");
Wladimir Palant 2016/10/06 08:06:14 filter_invalid_domain? We allow empty domains, but
kzar 2016/10/06 08:53:56 Done.
+
if (isException)
return new ElemHideException(text, domain, selector);
« no previous file with comments | « lib/elemHide.js ('k') | test/elemHide.js » ('j') | test/filterClasses.js » ('J')

Powered by Google App Engine
This is Rietveld