Support blacklist with port

jh-changes
Shin'ya Ueoka 6 years ago
parent 938fe9f752
commit 1bd2bf1ae3
  1. 4
      src/shared/blacklists.js
  2. 7
      test/shared/blacklists.test.js

@ -4,9 +4,9 @@ const includes = (blacklist, url) => {
let u = new URL(url); let u = new URL(url);
return blacklist.some((item) => { return blacklist.some((item) => {
if (!item.includes('/')) { if (!item.includes('/')) {
return re.fromWildcard(item).test(u.hostname); return re.fromWildcard(item).test(u.host);
} }
return re.fromWildcard(item).test(u.hostname + u.pathname); return re.fromWildcard(item).test(u.host + u.pathname);
}); });
}; };

@ -39,4 +39,11 @@ describe("shared/blacklist", () => {
expect(includes(blacklist, 'https://github.com/abcdef')).to.be.true; expect(includes(blacklist, 'https://github.com/abcdef')).to.be.true;
expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false; expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false;
}) })
it('matches address and port', () => {
let blacklist = ['127.0.0.1:8888'];
expect(includes(blacklist, 'http://127.0.0.1:8888/')).to.be.true;
expect(includes(blacklist, 'http://127.0.0.1:8888/hello')).to.be.true;
})
}); });