diff --git a/CHANGELOG.md b/CHANGELOG.md index 3465e55..906c1fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/test/e2e-specs.js b/test/e2e-specs.js index 36f4c7c..c11b244 100644 --- a/test/e2e-specs.js +++ b/test/e2e-specs.js @@ -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 // { diff --git a/www/ponyfills.js b/www/ponyfills.js index 67b9bbc..e49e6d7 100644 --- a/www/ponyfills.js +++ b/www/ponyfills.js @@ -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 ]);