diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-04-17 20:49:47 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-04-17 20:49:47 +0900 |
commit | 1bd2bf1ae3e78ee2814a8c30991d1d441ff4ddef (patch) | |
tree | 3569b67362f08caf26f66c16179e0f82508d2cf1 | |
parent | 938fe9f752e393f0ea21def020e849a51ea79300 (diff) |
Support blacklist with port
-rw-r--r-- | src/shared/blacklists.js | 4 | ||||
-rw-r--r-- | test/shared/blacklists.test.js | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/shared/blacklists.js b/src/shared/blacklists.js index 19ed3f1..61720c3 100644 --- a/src/shared/blacklists.js +++ b/src/shared/blacklists.js @@ -4,9 +4,9 @@ const includes = (blacklist, url) => { let u = new URL(url); return blacklist.some((item) => { 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); }); }; diff --git a/test/shared/blacklists.test.js b/test/shared/blacklists.test.js index 87e89c5..289ea0f 100644 --- a/test/shared/blacklists.test.js +++ b/test/shared/blacklists.test.js @@ -39,4 +39,11 @@ describe("shared/blacklist", () => { expect(includes(blacklist, 'https://github.com/abcdef')).to.be.true; 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; + }) }); |