Skip to content

Commit

Permalink
fix: preserve file path when parsing formdata (#2245)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmywarting authored Sep 4, 2023
1 parent 6653fca commit 92ddf0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fetch/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ function bodyMixinMethods (instance) {
try {
busboy = Busboy({
headers,
preservePath: true,
defParamCharset: 'utf8'
})
} catch (err) {
Expand Down
12 changes: 12 additions & 0 deletions test/fetch/client-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 92ddf0c

Please sign in to comment.