Skip to content

Commit

Permalink
fix(fetch): replace instanceof FormData check (nodejs#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
NMinhNguyen authored and metcoder95 committed Dec 26, 2022
1 parent 0be4178 commit f2e6b32
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fetch/body.js
Expand Up @@ -71,7 +71,7 @@ function extractBody (object, keepalive = false) {

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

Expand Down
2 changes: 2 additions & 0 deletions lib/fetch/formdata.js
Expand Up @@ -6,6 +6,8 @@ const { File, FileLike } = require('./file')
const { Blob } = require('buffer')

class FormData {
static name = 'FormData'

constructor (...args) {
if (args.length > 0 && !(args[0]?.constructor?.name === 'HTMLFormElement')) {
throw new TypeError(
Expand Down
6 changes: 6 additions & 0 deletions test/fetch/formdata.js
Expand Up @@ -216,3 +216,9 @@ test('formData toStringTag', (t) => {
t.equal(FormData.prototype[Symbol.toStringTag], 'FormData')
t.end()
})

test('formData.constructor.name', (t) => {
const form = new FormData()
t.equal(form.constructor.name, 'FormData')
t.end()
})

0 comments on commit f2e6b32

Please sign in to comment.