Skip to content

Commit

Permalink
fix(fetch): parse multipart form data non-ascii filed names (nodejs#1786
Browse files Browse the repository at this point in the history
)

Co-authored-by: surefire <surefire@cryptomile.net>
  • Loading branch information
2 people authored and anonrig committed Apr 4, 2023
1 parent 56ebc73 commit d46c8bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/fetch/body.js
Expand Up @@ -378,7 +378,10 @@ function bodyMixinMethods (instance) {
let busboy

try {
busboy = Busboy({ headers })
busboy = Busboy({
headers,
defParamCharset: 'utf8'
})
} catch (err) {
// Error due to headers:
throw Object.assign(new TypeError(), { cause: err })
Expand Down
20 changes: 20 additions & 0 deletions test/fetch/client-fetch.js
Expand Up @@ -227,6 +227,26 @@ test('multipart formdata base64', (t) => {
})
})

test('multipart fromdata non-ascii filed names', async (t) => {
t.plan(1)

const request = new Request('http://localhost', {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data; boundary=----formdata-undici-0.6204674738279623'
},
body:
'------formdata-undici-0.6204674738279623\r\n' +
'Content-Disposition: form-data; name="fiŝo"\r\n' +
'\r\n' +
'value1\r\n' +
'------formdata-undici-0.6204674738279623--'
})

const form = await request.formData()
t.equal(form.get('fiŝo'), 'value1')
})

test('busboy emit error', async (t) => {
t.plan(1)
const formData = new FormData()
Expand Down

0 comments on commit d46c8bf

Please sign in to comment.