From c98fbf93e9503bf40d199ef2adf31a15cf58c9b3 Mon Sep 17 00:00:00 2001 From: Mario Basic Date: Fri, 19 Jun 2015 13:03:54 +0200 Subject: [PATCH] Fixed bug with blacklist and whitelist. --- assets/js/components/Options.jsx | 11 +++++++---- assets/js/helpers/contains.js | 6 ++++++ public/js/app.js | 6 ++++++ public/js/events.js | 6 ++++++ public/js/options.js | 11 +++++++---- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/assets/js/components/Options.jsx b/assets/js/components/Options.jsx index 33d5bde..5753d56 100644 --- a/assets/js/components/Options.jsx +++ b/assets/js/components/Options.jsx @@ -71,20 +71,23 @@ var Options = React.createClass({ var theme = React.findDOMNode(this.refs.theme).value.trim(); var loggingType = React.findDOMNode(this.refs.loggingType).value.trim(); var loggingStyle = React.findDOMNode(this.refs.loggingStyle).value.trim(); + // Trimming blacklist and whitelist removes blank lines and spaces. + var blacklist = that.state.blacklist.trim(); + var whitelist = that.state.whitelist.trim(); // Sync options with google storage. chrome.storage.sync.set({ theme: theme, - blacklist: that.state.blacklist, - whitelist: that.state.whitelist, + blacklist: blacklist, + whitelist: whitelist, loggingType: loggingType, loggingStyle: loggingStyle }, function () { // Set state to be newly entered values. that.setState({ theme: theme, - blacklist: that.state.blacklist, - whitelist: that.state.whitelist, + blacklist: blacklist, + whitelist: whitelist, loggingType: loggingType, loggingStyle: loggingStyle, displayAlert: true diff --git a/assets/js/helpers/contains.js b/assets/js/helpers/contains.js index 2f9f7e9..05f2d3f 100644 --- a/assets/js/helpers/contains.js +++ b/assets/js/helpers/contains.js @@ -10,6 +10,12 @@ function contains(line, list) { var lines = list.split('\n'); for (var i = 0; i < lines.length; i ++) { + + // If by any chance one line in the list is empty or contains a blank space, ignore it + // It would probably be better to use regex here to detect blank space, but since + // this is not likely to be triggered anyway, there is no need for that yet. + if(lines[i] === '' || lines[i] === ' ') continue; + if (line.indexOf(lines[i]) > - 1) { return true; } diff --git a/public/js/app.js b/public/js/app.js index 1c2d6bd..435c2a9 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -959,6 +959,12 @@ function contains(line, list) { var lines = list.split('\n'); for (var i = 0; i < lines.length; i++) { + + // If by any chance one line in the list is empty or contains a blank space, ignore it + // It would probably be better to use regex here to detect blank space, but since + // this is not likely to be triggered anyway, there is no need for that yet. + if (lines[i] === '' || lines[i] === ' ') continue; + if (line.indexOf(lines[i]) > -1) { return true; } diff --git a/public/js/events.js b/public/js/events.js index 5031b85..d70937b 100644 --- a/public/js/events.js +++ b/public/js/events.js @@ -586,6 +586,12 @@ function contains(line, list) { var lines = list.split('\n'); for (var i = 0; i < lines.length; i++) { + + // If by any chance one line in the list is empty or contains a blank space, ignore it + // It would probably be better to use regex here to detect blank space, but since + // this is not likely to be triggered anyway, there is no need for that yet. + if (lines[i] === '' || lines[i] === ' ') continue; + if (line.indexOf(lines[i]) > -1) { return true; } diff --git a/public/js/options.js b/public/js/options.js index 8850509..fc869f1 100644 --- a/public/js/options.js +++ b/public/js/options.js @@ -117,20 +117,23 @@ var Options = React.createClass({ var theme = React.findDOMNode(this.refs.theme).value.trim(); var loggingType = React.findDOMNode(this.refs.loggingType).value.trim(); var loggingStyle = React.findDOMNode(this.refs.loggingStyle).value.trim(); + // Trimming blacklist and whitelist removes blank lines and spaces. + var blacklist = that.state.blacklist.trim(); + var whitelist = that.state.whitelist.trim(); // Sync options with google storage. chrome.storage.sync.set({ theme: theme, - blacklist: that.state.blacklist, - whitelist: that.state.whitelist, + blacklist: blacklist, + whitelist: whitelist, loggingType: loggingType, loggingStyle: loggingStyle }, function () { // Set state to be newly entered values. that.setState({ theme: theme, - blacklist: that.state.blacklist, - whitelist: that.state.whitelist, + blacklist: blacklist, + whitelist: whitelist, loggingType: loggingType, loggingStyle: loggingStyle, displayAlert: true