Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update types check #3342

Merged
merged 2 commits into from Dec 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/utils.js
Expand Up @@ -54,7 +54,7 @@ function isArrayBuffer(val) {
* @returns {boolean} True if value is an FormData, otherwise false
*/
function isFormData(val) {
return (typeof FormData !== 'undefined') && (val instanceof FormData);
return toString.call(val) === '[object FormData]';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of toString.call(val) in my React Native project returns [object Object] rather than [object FormData] which makes file upload fail with this change. See #4412

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue seems related too: form-data/form-data#396

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString#using_tostring_to_detect_object_class using this way to detect object class is unreliable, so maybe it shouldn't be used?

}

/**
Expand All @@ -68,7 +68,7 @@ function isArrayBufferView(val) {
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
result = ArrayBuffer.isView(val);
} else {
result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
}
return result;
}
Expand Down Expand Up @@ -175,7 +175,7 @@ function isStream(val) {
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
*/
function isURLSearchParams(val) {
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
return toString.call(val) === '[object URLSearchParams]';
}

/**
Expand Down