fix blacklist

This commit is contained in:
Alan Hamlett
2016-06-29 11:11:22 -07:00
parent 38c8a60698
commit 53b60eb90e
2 changed files with 14 additions and 12 deletions

View File

@@ -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;
}
}

View File

@@ -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);
});
});