Skip to content

Commit

Permalink
fix(api/internal/primitives.js): fix 'FormData' append/set for 'Objec…
Browse files Browse the repository at this point in the history
…t.create' 'File' instances
  • Loading branch information
jwerle committed Aug 20, 2024
1 parent c9c6d91 commit 7526c7f
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions api/internal/primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7526c7f

Please sign in to comment.