mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
fix(utils): make isFormData detection logic stricter to avoid unnecessary calling of the toString method on the target; (#5661)
This commit is contained in:
+9
-5
@@ -188,12 +188,16 @@ const isStream = (val) => isObject(val) && isFunction(val.pipe);
|
||||
* @returns {boolean} True if value is an FormData, otherwise false
|
||||
*/
|
||||
const isFormData = (thing) => {
|
||||
const pattern = '[object FormData]';
|
||||
let kind;
|
||||
return thing && (
|
||||
(typeof FormData === 'function' && thing instanceof FormData) ||
|
||||
toString.call(thing) === pattern ||
|
||||
(isFunction(thing.toString) && thing.toString() === pattern)
|
||||
);
|
||||
(typeof FormData === 'function' && thing instanceof FormData) || (
|
||||
isFunction(thing.append) && (
|
||||
(kind = kindOf(thing)) === 'formdata' ||
|
||||
// detect form-data instance
|
||||
(kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user