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: Addressed comment and added tests Created Nov. 20, 2014, 12:45 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
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') | qunit/tests/filterValidation.js » ('J')

Powered by Google App Engine
This is Rietveld