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

Unified Diff: background.js

Issue 5279235799252992: Issue 491 - Validate custom filters (Closed)
Patch Set: Created Nov. 18, 2014, 3:57 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 | block.js » ('j') | block.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -21,6 +21,7 @@
this.RegExpFilter = RegExpFilter;
this.BlockingFilter = BlockingFilter;
this.WhitelistFilter = WhitelistFilter;
+ this.InvalidFilter = InvalidFilter;
}
with(require("subscriptionClasses"))
{
@@ -524,11 +525,23 @@
}
break;
case "add-filters":
- if (msg.filters && msg.filters.length)
+ var filters = [];
+
kzar 2014/11/18 16:32:10 How come you don't check that msg.filters and msg.
Sebastian Noack 2014/11/18 17:42:55 There was no point in checking it in the first pla
+ for (var i = 0; i < msg.filters.length; i++)
{
- for (var i = 0; i < msg.filters.length; i++)
- FilterStorage.addFilter(Filter.fromText(msg.filters[i]));
+ var filter = Filter.fromText(msg.filters[i], true);
kzar 2014/11/18 16:32:10 Instead of having this separate filter variable ho
Sebastian Noack 2014/11/18 17:42:55 We have to access the filter object 3 times (or 2
+ if (filter instanceof InvalidFilter)
+ {
+ sendResponse({status: "invalid", error: filter.reason});
+ return;
+ }
+ filters.push(filter);
}
+
+ for (var i = 0; i < filters.length; i++)
kzar 2014/11/18 16:32:10 You've re-declared the `i` variable here.
+ FilterStorage.addFilter(filters[i]);
+
+ sendResponse({status: "ok"});
break;
case "add-subscription":
ext.showOptions(function(page)
« no previous file with comments | « no previous file | block.js » ('j') | block.js » ('J')

Powered by Google App Engine
This is Rietveld