Skip to content

Commit 048c0c6

Browse files
authored
Apply bugfix in url regex (#5)
* back-porting fastify/fast-proxy#76
1 parent f5501c5 commit 048c0c6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ function filterHeaders (headers, filter) {
8989
}
9090

9191
function buildURL (source = '', reqBase) {
92-
// issue ref: https://github.com/fastify/fast-proxy/issues/42
93-
const cleanSource = source.replace(/\/+/g, '/')
92+
// issue ref: https://github.com/fastify/fast-proxy/issues/42, https://github.com/fastify/fast-proxy/issues/76
93+
let i = 0
94+
while (source[i] === '/') {
95+
i++
96+
}
97+
const cleanSource = i > 0 ? '/' + source.substring(i) : source
9498

9599
return new URL(cleanSource, reqBase)
96100
}

test/10.build-url.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ describe('buildURL', () => {
2727
expect(url.href).to.equal('http://localhost/hi')
2828
})
2929

30+
it('should not strip double slashes from query parameters', function () {
31+
const url = buildURL('/hi?bye=https%3A//example.com', 'http://localhost')
32+
33+
expect(url.origin).to.equal('http://localhost')
34+
expect(url.pathname).to.equal('/hi')
35+
expect(url.href).to.equal('http://localhost/hi?bye=https%3A//example.com')
36+
})
37+
3038
it('should produce valid URL (1 param)', function () {
3139
const url = buildURL('http://localhost/hi')
3240

0 commit comments

Comments
 (0)