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. 19, 2014, 3:26 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 | « _locales/en_US/messages.json ('k') | block.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -43,6 +43,7 @@
var Utils = require("utils").Utils;
var Notification = require("notification").Notification;
var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNotification;
+var parseFilters = require("filterValidation").parseFilters;
// Some types cannot be distinguished
RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
@@ -524,11 +525,21 @@
}
break;
case "add-filters":
- if (msg.filters && msg.filters.length)
+ var filters;
+ try
{
- for (var i = 0; i < msg.filters.length; i++)
- FilterStorage.addFilter(Filter.fromText(msg.filters[i]));
+ filters = parseFilters(msg.text);
}
+ catch (error)
+ {
+ sendResponse({status: "invalid", error: error});
+ break;
+ }
+
+ for (var i = 0; i < filters.length; i++)
+ FilterStorage.addFilter(filters[i]);
+
+ sendResponse({status: "ok"});
break;
case "add-subscription":
ext.showOptions(function(page)
« no previous file with comments | « _locales/en_US/messages.json ('k') | block.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld