mirror of
https://github.com/cypress-io/cypress.git
synced 2026-05-04 22:10:40 -05:00
Before XHR URLs are whitelisted, strip query params and hashes (#7742)
This commit is contained in:
@@ -2296,6 +2296,34 @@ describe('src/cy/commands/xhr', () => {
|
||||
expect(resp).to.eq('{ \'bar\' }\n')
|
||||
})
|
||||
})
|
||||
|
||||
// https://github.com/cypress-io/cypress/issues/7280
|
||||
it('ignores query params when whitelisting routes', () => {
|
||||
cy.server()
|
||||
cy.route(/url-with-query-param/, { foo: 'bar' }).as('getQueryParam')
|
||||
cy.window().then((win) => {
|
||||
win.$.get('/url-with-query-param?resource=foo.js')
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
cy.wait('@getQueryParam').its('response.body')
|
||||
.should('deep.equal', { foo: 'bar' })
|
||||
})
|
||||
|
||||
// https://github.com/cypress-io/cypress/issues/7280
|
||||
it('ignores hashes when whitelisting routes', () => {
|
||||
cy.server()
|
||||
cy.route(/url-with-hash/, { foo: 'bar' }).as('getHash')
|
||||
cy.window().then((win) => {
|
||||
win.$.get('/url-with-hash#foo.js')
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
cy.wait('@getHash').its('response.body')
|
||||
.should('deep.equal', { foo: 'bar' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('route setup', () => {
|
||||
|
||||
@@ -66,8 +66,16 @@ const warnOnForce404Default = (obj) => {
|
||||
}
|
||||
|
||||
const whitelist = (xhr) => {
|
||||
const url = new URL(xhr.url)
|
||||
|
||||
// https://github.com/cypress-io/cypress/issues/7280
|
||||
// we want to strip the xhr's URL of any hash and query params before
|
||||
// checking the REGEX for matching file extensions
|
||||
url.search = ''
|
||||
url.hash = ''
|
||||
|
||||
// whitelist if we're GET + looks like we're fetching regular resources
|
||||
return xhr.method === 'GET' && regularResourcesRe.test(xhr.url)
|
||||
return xhr.method === 'GET' && regularResourcesRe.test(url.href)
|
||||
}
|
||||
|
||||
const serverDefaults = {
|
||||
|
||||
Reference in New Issue
Block a user