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

Unified Diff: options.js

Issue 5279235799252992: Issue 491 - Validate custom filters (Closed)
Patch Set: Improved test messages Created Nov. 21, 2014, 8:07 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 | « metadata.common ('k') | qunit/index.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: options.js
===================================================================
--- a/options.js
+++ b/options.js
@@ -29,6 +29,11 @@
this.SpecialSubscription = SpecialSubscription;
this.DownloadableSubscription = DownloadableSubscription;
}
+with(require("filterValidation"))
+{
+ this.parseFilter = parseFilter;
+ this.parseFilters = parseFilters;
+}
var FilterStorage = require("filterStorage").FilterStorage;
var FilterNotifier = require("filterNotifier").FilterNotifier;
var Prefs = require("prefs").Prefs;
@@ -472,12 +477,23 @@
{
event.preventDefault();
- var filterText = Filter.normalize(document.getElementById("newFilter").value);
- document.getElementById("newFilter").value = "";
- if (!filterText)
+ var element = document.getElementById("newFilter");
+ var filter;
+
+ try
+ {
+ filter = parseFilter(element.value);
+ }
+ catch (error)
+ {
+ alert(error);
return;
+ }
- FilterStorage.addFilter(Filter.fromText(filterText));
+ if (filter)
+ FilterStorage.addFilter(filter);
+
+ element.value = "";
}
// Removes currently selected whitelisted domains
@@ -529,21 +545,25 @@
// Imports filters in the raw text box
function importRawFiltersText()
{
- $("#rawFilters").hide();
- var filters = document.getElementById("rawFiltersText").value.split("\n");
+ var text = document.getElementById("rawFiltersText").value;
+
+ var add;
+ try
+ {
+ add = parseFilters(text, true);
+ }
+ catch (error)
+ {
+ alert(error);
+ return;
+ }
+
var seenFilter = {__proto__: null};
- for (var i = 0; i < filters.length; i++)
+ for (var i = 0; i < add.length; i++)
{
- var text = Filter.normalize(filters[i]);
- if (!text)
- continue;
-
- // Don't import filter list header
- if (/^\[/.test(text))
- continue;
-
- FilterStorage.addFilter(Filter.fromText(text));
- seenFilter[text] = true;
+ var filter = add[i];
+ FilterStorage.addFilter(filter);
+ seenFilter[filter.text] = null;
}
var remove = [];
@@ -563,8 +583,11 @@
remove.push(filter);
}
}
+
for (var i = 0; i < remove.length; i++)
FilterStorage.removeFilter(remove[i]);
+
+ $("#rawFilters").hide();
}
// Called when user explicitly requests filter list updates
« no previous file with comments | « metadata.common ('k') | qunit/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld