fix #300: FormData object containing null or undefined value is not serialized correctly

This commit is contained in:
Sefa Ilkimen 2020-02-03 02:46:31 +01:00
parent ab9dad8f46
commit 23a98ae491
No known key found for this signature in database
GPG Key ID: 4AB0B60A9B5E59F5
3 changed files with 25 additions and 1 deletions

View File

@ -4,6 +4,7 @@
- Fixed #296: multipart requests are not serialized on browser platform
- Fixed #301: data is not decoded correctly when responseType is "json" (thanks antikalk)
- Fixed #300: FormData object containing null or undefined value is not serialized correctly
## 2.4.0

View File

@ -923,6 +923,29 @@ const tests = [
});
}
},
{
description: 'should serialize FormData instance correctly when it contains null or undefined value #300',
expected: 'resolved: {"status":200, ...',
before: helpers.setMultipartSerializer,
func: function (resolve, reject) {
var ponyfills = cordova.plugin.http.ponyfills;
var formData = new ponyfills.FormData();
formData.append('myNullValue', null);
formData.append('myUndefinedValue', undefined);
var url = 'https://httpbin.org/anything';
var options = { method: 'post', data: formData };
cordova.plugin.http.sendRequest(url, options, resolve, reject);
},
validationFunc: function (driver, result) {
helpers.checkResult(result, 'resolved');
result.data.status.should.be.equal(200);
JSON.parse(result.data.data).form.should.be.eql({
myNullValue: 'null',
myUndefinedValue: 'undefined'
});
}
},
// TODO: not ready yet
// {

View File

@ -18,7 +18,7 @@ module.exports = function init(global) {
value.lastModifiedDate = new Date();
value.name = filename || '';
} else {
value = value.toString ? value.toString() : value;
value = String(value);
}
this.__items.push([ name, value ]);