diff --git a/assets/js/helpers/contains.js b/assets/js/helpers/contains.js index 760faa5..cd9c53f 100644 --- a/assets/js/helpers/contains.js +++ b/assets/js/helpers/contains.js @@ -1,12 +1,12 @@ /** * Creates an array from list using \n as delimiter - * and checks if the str is located in the list. + * and checks if any element in list is contained in the url. * - * @param str + * @param url * @param list * @returns {boolean} */ -function contains(str, list) { +function contains(url, list) { var lines = list.split('\n'); for (var i = 0; i < lines.length; i ++) { @@ -17,8 +17,8 @@ function contains(str, list) { // If by any chance one line in the list is empty, ignore it if(cleanLine === '') continue; - // If current line contains the str return true - if (cleanLine.indexOf(str) > -1) { + // If url contains the current line return true + if (url.indexOf(cleanLine) > -1) { return true; } } diff --git a/tests/helpers/contains.spec.js b/tests/helpers/contains.spec.js index 307fc86..40994eb 100644 --- a/tests/helpers/contains.spec.js +++ b/tests/helpers/contains.spec.js @@ -8,17 +8,19 @@ describe('contains', function() { expect(contains).to.be.a('function'); }); - it('should find the line and return true', function() { + it('should match url against blacklist and return true', function() { - var list = ".app\ntest.com"; + var list = "localhost\ntest.com"; - expect(contains('.app', list)).to.equal(true); + var url = 'http://localhost/fooapp'; + expect(contains(url, list)).to.equal(true); }); - it('should not find the line and it should return false', function() { + it('should not match url against blacklist and return false', function() { - var list = ".app\ntest.com"; + var list = "localhost\ntest.com"; - expect(contains('.app2', list)).to.equal(false); + var url = 'http://localhost/fooapp'; + expect(contains('http://localhost2/fooapp', list)).to.equal(false); }); -}); \ No newline at end of file +});