-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix filename* parsing * fixup
- Loading branch information
Showing
3 changed files
with
130 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict' | ||
|
||
const { test } = require('node:test') | ||
const assert = require('node:assert') | ||
const { Response } = require('../..') | ||
|
||
// https://github.com/nodejs/undici/issues/3760 | ||
test('filename* parameter is parsed properly', async (t) => { | ||
const response = new Response([ | ||
'--83d82e0d-9ced-44c0-ac79-4e66a827415b\r\n' + | ||
'Content-Type: text/plain\r\n' + | ||
'Content-Disposition: form-data; name="file"; filename*=UTF-8\'\'%e2%82%ac%20rates\r\n' + | ||
'\r\n' + | ||
'testabc\r\n' + | ||
'--83d82e0d-9ced-44c0-ac79-4e66a827415b--\r\n' + | ||
'\r\n' | ||
].join(''), { | ||
headers: { | ||
'content-type': 'multipart/form-data; boundary="83d82e0d-9ced-44c0-ac79-4e66a827415b"' | ||
} | ||
}) | ||
|
||
const fd = await response.formData() | ||
assert.deepEqual(fd.get('file').name, '€ rates') | ||
}) | ||
|
||
test('whitespace after filename[*]= is ignored', async () => { | ||
for (const response of [ | ||
new Response([ | ||
'--83d82e0d-9ced-44c0-ac79-4e66a827415b\r\n' + | ||
'Content-Type: text/plain\r\n' + | ||
'Content-Disposition: form-data; name="file"; filename*= utf-8\'\'hello\r\n' + | ||
'\r\n' + | ||
'testabc\r\n' + | ||
'--83d82e0d-9ced-44c0-ac79-4e66a827415b--\r\n' + | ||
'\r\n' | ||
].join(''), { | ||
headers: { | ||
'content-type': 'multipart/form-data; boundary="83d82e0d-9ced-44c0-ac79-4e66a827415b"' | ||
} | ||
}), | ||
new Response([ | ||
'--83d82e0d-9ced-44c0-ac79-4e66a827415b\r\n' + | ||
'Content-Type: text/plain\r\n' + | ||
'Content-Disposition: form-data; name="file"; filename= "hello"\r\n' + | ||
'\r\n' + | ||
'testabc\r\n' + | ||
'--83d82e0d-9ced-44c0-ac79-4e66a827415b--\r\n' + | ||
'\r\n' | ||
].join(''), { | ||
headers: { | ||
'content-type': 'multipart/form-data; boundary="83d82e0d-9ced-44c0-ac79-4e66a827415b"' | ||
} | ||
}) | ||
]) { | ||
const fd = await response.formData() | ||
assert.deepEqual(fd.get('file').name, 'hello') | ||
} | ||
}) |