From 7526c7f36e9109a8846df84b57106e38fee81d4f Mon Sep 17 00:00:00 2001 From: Joseph Werle Date: Tue, 20 Aug 2024 19:14:34 +0200 Subject: [PATCH] fix(api/internal/primitives.js): fix 'FormData' append/set for 'Object.create' 'File' instances --- api/internal/primitives.js | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/api/internal/primitives.js b/api/internal/primitives.js index 646fb496e8..8c29a5d02b 100644 --- a/api/internal/primitives.js +++ b/api/internal/primitives.js @@ -326,6 +326,52 @@ export function init () { // WebAssembly install(WebAssembly, globalThis.WebAssembly, 'WebAssembly') + // quirks + if (typeof globalThis.FormData === 'function') { + const { append, set } = FormData.prototype + Object.defineProperties(FormData.prototype, { + append: { + configurable: true, + enumerable: true, + value (name, value, filename) { + if ( // check for 'File' + typeof value === 'object' && + value instanceof Blob && + typeof value.name === 'string' + ) { + if (!filename) { + filename = value.name + } + + value = value.slice() + } + + return append.call(this, name, value, filename) + } + }, + + set: { + configurable: true, + enumerable: true, + value (name, value, filename) { + if ( // check for 'File' + typeof value === 'object' && + value instanceof Blob && + typeof value.name === 'string' + ) { + if (!filename) { + filename = value.name + } + + value = value.slice() + } + + return set.call(this, name, value, filename) + } + }, + }) + } + applied = true if (!Error.captureStackTrace) {