2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

fix: safe FormData detection for WeChat Mini Program (#7306) (#7324)

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Shiwaangee
2026-02-14 21:12:56 +05:30
committed by GitHub
parent 822e3e40b4
commit 672491db34
+19 -9
View File
@@ -220,17 +220,27 @@ const isStream = (val) => isObject(val) && isFunction(val.pipe);
*
* @returns {boolean} True if value is an FormData, otherwise false
*/
function getGlobal() {
if (typeof globalThis !== 'undefined') return globalThis;
if (typeof self !== 'undefined') return self;
if (typeof window !== 'undefined') return window;
if (typeof global !== 'undefined') return global;
return {};
}
const G = getGlobal();
const FormDataCtor = typeof G.FormData !== 'undefined' ? G.FormData : undefined;
const isFormData = (thing) => {
let kind;
return (
thing &&
((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]'))))
return thing && (
(FormDataCtor && thing instanceof FormDataCtor) || (
isFunction(thing.append) && (
(kind = kindOf(thing)) === 'formdata' ||
// detect form-data instance
(kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
)
)
);
};