From bae93dceb0708854206557ccdce3ad6f7673e459 Mon Sep 17 00:00:00 2001 From: Livia Medeiros Date: Fri, 28 Jul 2023 18:09:42 +0900 Subject: [PATCH] fix: make multipart/form-data boundary string more consistent (#2196) --- lib/fetch/body.js | 2 +- test/client-request.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fetch/body.js b/lib/fetch/body.js index db450ee6bd4..0c7b8b65363 100644 --- a/lib/fetch/body.js +++ b/lib/fetch/body.js @@ -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 */ diff --git a/test/client-request.js b/test/client-request.js index 626db41187a..703cedf6803 100644 --- a/test/client-request.js +++ b/test/client-request.js @@ -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 = []