Skip to content

Commit

Permalink
fix: make multipart/form-data boundary string more consistent (#2196)
Browse files Browse the repository at this point in the history
  • Loading branch information
LiviaMedeiros committed Jul 28, 2023
1 parent 1037578 commit bae93dc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/fetch/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function extractBody (object, keepalive = false) {
// Set source to a copy of the bytes held by object.
source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength))
} else if (util.isFormDataLike(object)) {
const boundary = `----formdata-undici-${Math.random()}`.replace('.', '').slice(0, 32)
const boundary = `----formdata-undici-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}`
const prefix = `--${boundary}\r\nContent-Disposition: form-data`

/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
Expand Down
2 changes: 1 addition & 1 deletion test/client-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ test('request with FormData body', { skip: nodeMajor < 16 }, (t) => {
const server = createServer(async (req, res) => {
const contentType = req.headers['content-type']
// ensure we received a multipart/form-data header
t.ok(/^multipart\/form-data; boundary=-+formdata-undici-0.\d+$/.test(contentType))
t.ok(/^multipart\/form-data; boundary=-+formdata-undici-0\d+$/.test(contentType))

const chunks = []

Expand Down

0 comments on commit bae93dc

Please sign in to comment.