Skip to content

Commit d023b2d

Browse files
authored
fix(fetch): replace instanceof FormData check (nodejs#1457)
1 parent 1f2cca6 commit d023b2d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/fetch/body.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function extractBody (object, keepalive = false) {
7171

7272
// Set source to a copy of the bytes held by object.
7373
source = new Uint8Array(object)
74-
} else if (object instanceof FormData || util.isFormDataLike(object)) {
74+
} else if (util.isFormDataLike(object)) {
7575
const boundary = '----formdata-undici-' + Math.random()
7676
const prefix = `--${boundary}\r\nContent-Disposition: form-data`
7777

lib/fetch/formdata.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const { File, FileLike } = require('./file')
66
const { Blob } = require('buffer')
77

88
class FormData {
9+
static name = 'FormData'
10+
911
constructor (...args) {
1012
if (args.length > 0 && !(args[0]?.constructor?.name === 'HTMLFormElement')) {
1113
throw new TypeError(

test/fetch/formdata.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,9 @@ test('formData toStringTag', (t) => {
216216
t.equal(FormData.prototype[Symbol.toStringTag], 'FormData')
217217
t.end()
218218
})
219+
220+
test('formData.constructor.name', (t) => {
221+
const form = new FormData()
222+
t.equal(form.constructor.name, 'FormData')
223+
t.end()
224+
})

0 commit comments

Comments
 (0)