From 08edcbe46970695c1e7c350f57e9e46a2d6776aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20W=C3=A4rting?= Date: Mon, 4 Sep 2023 16:02:23 +0200 Subject: [PATCH] fix: preserve file path when parsing formdata (#2245) --- lib/fetch/body.js | 1 + test/fetch/client-fetch.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/fetch/body.js b/lib/fetch/body.js index 11b945d18bf..105eb553157 100644 --- a/lib/fetch/body.js +++ b/lib/fetch/body.js @@ -387,6 +387,7 @@ function bodyMixinMethods (instance) { try { busboy = Busboy({ headers, + preservePath: true, defParamCharset: 'utf8' }) } catch (err) { diff --git a/test/fetch/client-fetch.js b/test/fetch/client-fetch.js index 048b76a9f78..9009d547ec6 100644 --- a/test/fetch/client-fetch.js +++ b/test/fetch/client-fetch.js @@ -272,6 +272,18 @@ test('busboy emit error', async (t) => { await t.rejects(res.formData(), 'Unexpected end of multipart data') }) +// https://github.com/nodejs/undici/issues/2244 +test('parsing formData preserve full path on files', async (t) => { + t.plan(1) + const formData = new FormData() + formData.append('field1', new File(['foo'], 'a/b/c/foo.txt')) + + const tempRes = new Response(formData) + const form = await tempRes.formData() + + t.equal(form.get('field1').name, 'a/b/c/foo.txt') +}) + test('urlencoded formData', (t) => { t.plan(2)