Skip to content

Commit

Permalink
fix: improve isFormDataLike compat (#1953)
Browse files Browse the repository at this point in the history
Fixes: #1952
  • Loading branch information
ronag authored Feb 21, 2023
1 parent 5851019 commit ab494d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,20 +375,17 @@ function ReadableStreamFrom (iterable) {

// The chunk should be a FormData instance and contains
// all the required methods.
function isFormDataLike (chunk) {
return (chunk &&
chunk.constructor && chunk.constructor.name === 'FormData' &&
typeof chunk === 'object' &&
(typeof chunk.append === 'function' &&
typeof chunk.delete === 'function' &&
typeof chunk.get === 'function' &&
typeof chunk.getAll === 'function' &&
typeof chunk.has === 'function' &&
typeof chunk.set === 'function' &&
typeof chunk.entries === 'function' &&
typeof chunk.keys === 'function' &&
typeof chunk.values === 'function' &&
typeof chunk.forEach === 'function')
function isFormDataLike (object) {
return (
object &&
typeof object === 'object' &&
typeof object.append === 'function' &&
typeof object.delete === 'function' &&
typeof object.get === 'function' &&
typeof object.getAll === 'function' &&
typeof object.has === 'function' &&
typeof object.set === 'function' &&
object[Symbol.toStringTag] === 'FormData'
)
}

Expand Down
4 changes: 4 additions & 0 deletions test/fetch/formdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ test('FormData should be compatible with third-party libraries', (t) => {
this.data = []
}

get [Symbol.toStringTag] () {
return 'FormData'
}

append () {}
delete () {}
get () {}
Expand Down

0 comments on commit ab494d2

Please sign in to comment.