Skip to content

Commit

Permalink
fix: incorrect http(s) regexp (#1212)
Browse files Browse the repository at this point in the history
* fix: incorrect http(s) regexp

* Add more test for requestBadPort
  • Loading branch information
cjh980402 authored Feb 8, 2022
1 parent 6bbc0b0 commit d94dc15
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function requestBadPort (request) {

// 2. If url’s scheme is an HTTP(S) scheme and url’s port is a bad port,
// then return blocked.
if (/^http?s/.test(url.protocol) && badPorts.includes(url.port)) {
if (/^https?:/.test(url.protocol) && badPorts.includes(url.port)) {
return 'blocked'
}

Expand Down
5 changes: 4 additions & 1 deletion test/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ test('responseLocationURL', (t) => {
})

test('requestBadPort', (t) => {
t.plan(2)
t.plan(3)

t.equal('allowed', util.requestBadPort({
urlList: [new URL('https://asd')]
}))
t.equal('blocked', util.requestBadPort({
urlList: [new URL('http://asd:7')]
}))
t.equal('blocked', util.requestBadPort({
urlList: [new URL('https://asd:7')]
}))
Expand Down

0 comments on commit d94dc15

Please sign in to comment.