Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fetch): parse multipart/form-data non-ASCII field names #1786

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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