From a658ab3016c8dc23dd0e023b9e9814aaeac6a842 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Sat, 5 Oct 2024 19:23:19 +0200 Subject: [PATCH] test: add test to ensure full type when parsing multipart/form-data' (#3683) --- test/issue-2283.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/issue-2283.js diff --git a/test/issue-2283.js b/test/issue-2283.js new file mode 100644 index 00000000000..f2c55145cc7 --- /dev/null +++ b/test/issue-2283.js @@ -0,0 +1,26 @@ +'use strict' + +const { tspl } = require('@matteo.collina/tspl') +const { describe, test } = require('node:test') +const { FormData, Response } = require('..') + +describe('https://github.com/nodejs/undici/issues/2283', () => { + test('preserve full type when parsing multipart/form-data', async (t) => { + t = tspl(t, { plan: 2 }) + const testBlob = new Blob(['123'], { type: 'text/plain;charset=utf-8' }) + const fd = new FormData() + fd.set('x', testBlob) + const res = new Response(fd) + res.clone().text().then(body => + // Just making sure that it contains ;charset=utf-8 + t.ok(body.includes('text/plain;charset=utf-8')) + ) + + new Response(fd).formData().then(fd => { + // returns just 'text/plain' + t.ok(fd.get('x').type === 'text/plain;charset=utf-8') + }) + + await t.completed + }) +})