mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2024-10-06 09:12:13 +08:00
fix #300: FormData object containing null or undefined value is not serialized correctly
This commit is contained in:
parent
ab9dad8f46
commit
23a98ae491
@ -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
|
||||
|
||||
|
@ -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
|
||||
// {
|
||||
|
@ -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 ]);
|
||||
|
Loading…
Reference in New Issue
Block a user