Skip to content

Commit

Permalink
fix: decode urls in prerequest
Browse files Browse the repository at this point in the history
  • Loading branch information
mschile committed Nov 16, 2023
1 parent d54a1e9 commit b2296b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/proxy/lib/http/util/prerequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class PreRequests {

addPending (browserPreRequest: BrowserPreRequest) {
metrics.browserPreRequestsReceived++
const key = `${browserPreRequest.method}-${browserPreRequest.url}`
const key = `${browserPreRequest.method}-${decodeURI(browserPreRequest.url)}`
const pendingRequest = this.pendingRequests.shift(key)

if (pendingRequest) {
Expand Down Expand Up @@ -193,7 +193,7 @@ export class PreRequests {
}

addPendingUrlWithoutPreRequest (url: string) {
const key = `GET-${url}`
const key = `GET-${decodeURI(url)}`
const pendingRequest = this.pendingRequests.shift(key)

if (pendingRequest) {
Expand Down Expand Up @@ -236,7 +236,7 @@ export class PreRequests {
const proxyRequestReceivedTimestamp = performance.now() + performance.timeOrigin

metrics.proxyRequestsReceived++
const key = `${req.method}-${req.proxiedUrl}`
const key = `${req.method}-${decodeURI(req.proxiedUrl)}`
const pendingPreRequest = this.pendingPreRequests.shift(key)

if (pendingPreRequest) {
Expand Down
21 changes: 21 additions & 0 deletions packages/proxy/test/unit/http/util/prerequests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,25 @@ describe('http/util/prerequests', () => {

expect(callbackCalled).to.be.true
})

it('decodes the proxied url', () => {
preRequests.get({ proxiedUrl: 'foo%7Cbar', method: 'GET', headers: {} } as CypressIncomingRequest, () => {}, () => {})

expect(preRequests.pendingRequests.length).to.eq(1)
expect(preRequests.pendingRequests.shift('GET-foo|bar')).not.to.be.undefined
})

it('decodes the pending url without pre-request', () => {
preRequests.addPendingUrlWithoutPreRequest('foo%7Cbar')

expect(preRequests.pendingUrlsWithoutPreRequests.length).to.eq(1)
expect(preRequests.pendingUrlsWithoutPreRequests.shift('GET-foo|bar')).not.to.be.undefined
})

it('decodes pending url', () => {
preRequests.addPending({ requestId: '1234', url: 'foo%7Cbar', method: 'GET' } as BrowserPreRequest)

expect(preRequests.pendingPreRequests.length).to.eq(1)
expect(preRequests.pendingPreRequests.shift('GET-foo|bar')).not.to.be.undefined
})
})

0 comments on commit b2296b7

Please sign in to comment.