From c8eb05181cebc8b233e84253213e2cd31d4860fb Mon Sep 17 00:00:00 2001 From: ahmad-kashkoush Date: Thu, 13 Feb 2025 16:18:39 +0200 Subject: [PATCH] add tests --- package.json | 3 +- test/busboy/issue-3760.js | 59 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/busboy/issue-3760.js diff --git a/package.json b/package.json index ab4dcf422f1..56e0fce0934 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,8 @@ "generate-pem": "node scripts/generate-pem.js", "lint": "eslint --cache", "lint:fix": "eslint --fix --cache", - "test": "npm run test:javascript && cross-env NODE_V8_COVERAGE= npm run test:typescript", + "test": "borp -p test/busboy/issue-3760.js", + "test:alll": "npm run test:javascript && cross-env NODE_V8_COVERAGE= npm run test:typescript", "test:javascript": "npm run test:javascript:no-jest && npm run test:jest", "test:javascript:no-jest": "npm run generate-pem && npm run test:unit && npm run test:node-fetch && npm run test:cache && npm run test:cache-interceptor && npm run test:interceptors && npm run test:fetch && npm run test:cookies && npm run test:eventsource && npm run test:wpt && npm run test:websocket && npm run test:node-test", "test:javascript:without-intl": "npm run test:javascript:no-jest", diff --git a/test/busboy/issue-3760.js b/test/busboy/issue-3760.js new file mode 100644 index 00000000000..d37852c8fac --- /dev/null +++ b/test/busboy/issue-3760.js @@ -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') + } +})