From b2296b7a3534a1db465cee3c55aa823fa5b85d8f Mon Sep 17 00:00:00 2001 From: Matthew Schile Date: Thu, 16 Nov 2023 14:36:51 -0700 Subject: [PATCH] fix: decode urls in prerequest --- packages/proxy/lib/http/util/prerequests.ts | 6 +++--- .../test/unit/http/util/prerequests.spec.ts | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/proxy/lib/http/util/prerequests.ts b/packages/proxy/lib/http/util/prerequests.ts index cbdd41f9a13f..86b2cd7f9f30 100644 --- a/packages/proxy/lib/http/util/prerequests.ts +++ b/packages/proxy/lib/http/util/prerequests.ts @@ -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) { @@ -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) { @@ -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) { diff --git a/packages/proxy/test/unit/http/util/prerequests.spec.ts b/packages/proxy/test/unit/http/util/prerequests.spec.ts index 391a73ef957d..37d2b9b966a8 100644 --- a/packages/proxy/test/unit/http/util/prerequests.spec.ts +++ b/packages/proxy/test/unit/http/util/prerequests.spec.ts @@ -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 + }) })