mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-24 07:59:12 -05:00
fix: treat form-data bodies as binary (#20144)
This commit is contained in:
@@ -251,6 +251,10 @@ export function getBodyEncoding (req: CyHttpMessages.IncomingRequest): BodyEncod
|
||||
if (contentType.includes('charset=utf-8') || contentType.includes('charset="utf-8"')) {
|
||||
return 'utf8'
|
||||
}
|
||||
|
||||
if (contentType.includes('multipart/form-data')) {
|
||||
return 'binary'
|
||||
}
|
||||
}
|
||||
|
||||
// with fallback to inspecting the buffer using
|
||||
|
||||
@@ -69,5 +69,19 @@ describe('net-stubbing util', () => {
|
||||
|
||||
expect(getBodyEncoding(req), 'image').to.equal('binary')
|
||||
})
|
||||
|
||||
it('returns binary for form-data bodies', () => {
|
||||
const formDataRequest = {
|
||||
body: Buffer.from('hello world'),
|
||||
headers: {
|
||||
'content-type': 'multipart/form-data',
|
||||
},
|
||||
method: 'POST',
|
||||
url: 'somewhere',
|
||||
httpVersion: '1.1',
|
||||
}
|
||||
|
||||
expect(getBodyEncoding(formDataRequest)).to.equal('binary')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user