diff --git a/lib/helpers/toFormData.js b/lib/helpers/toFormData.js index 6dcb9d2337..7eb9465e00 100644 --- a/lib/helpers/toFormData.js +++ b/lib/helpers/toFormData.js @@ -118,7 +118,7 @@ function toFormData(obj, formData, options) { key = removeBrackets(key); arr.forEach(function each(el, index) { - !utils.isUndefined(el) && formData.append( + !(utils.isUndefined(el) || el === null) && formData.append( // eslint-disable-next-line no-nested-ternary indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'), convertValue(el) @@ -155,7 +155,7 @@ function toFormData(obj, formData, options) { stack.push(value); utils.forEach(value, function each(el, key) { - var result = !utils.isUndefined(el) && visitor.call( + var result = !(utils.isUndefined(el) || el === null) && visitor.call( formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers ); diff --git a/test/specs/helpers/buildURL.spec.js b/test/specs/helpers/buildURL.spec.js index 6ddba8f009..fd55dcce4c 100644 --- a/test/specs/helpers/buildURL.spec.js +++ b/test/specs/helpers/buildURL.spec.js @@ -7,9 +7,13 @@ describe('helpers::buildURL', function () { }); it('should support params', function () { - expect(buildURL('/foo', { - foo: 'bar' - })).toEqual('/foo?foo=bar'); + expect( + buildURL("/foo", { + foo: "bar", + isUndefined: undefined, + isNull: null, + }) + ).toEqual("/foo?foo=bar"); }); it('should support object params', function () { @@ -29,9 +33,11 @@ describe('helpers::buildURL', function () { }); it('should support array params', function () { - expect(buildURL('/foo', { - foo: ['bar', 'baz'] - })).toEqual('/foo?foo[]=bar&foo[]=baz'); + expect( + buildURL("/foo", { + foo: ["bar", "baz", null, undefined], + }) + ).toEqual("/foo?foo[]=bar&foo[]=baz"); }); it('should support special char params', function () {