diff --git a/src/client.js b/src/client.js index 9260bcbea..319011ab1 100644 --- a/src/client.js +++ b/src/client.js @@ -192,7 +192,9 @@ request.types = { */ request.serialize = { - 'application/x-www-form-urlencoded': qs.stringify, + 'application/x-www-form-urlencoded': (obj) => { + return qs.stringify(obj, { indices: false, strictNullHandling: true }); + }, 'application/json': safeStringify }; diff --git a/src/node/index.js b/src/node/index.js index 74b357005..12b7e3176 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -99,7 +99,9 @@ exports.protocols = { */ exports.serialize = { - 'application/x-www-form-urlencoded': qs.stringify, + 'application/x-www-form-urlencoded': (obj) => { + return qs.stringify(obj, { indices: false, strictNullHandling: true }); + }, 'application/json': safeStringify }; diff --git a/test/client/serialize.js b/test/client/serialize.js index fe4ec91d8..8fdcadde5 100644 --- a/test/client/serialize.js +++ b/test/client/serialize.js @@ -38,6 +38,7 @@ describe('request.serializeObject()', () => { serialize({ '&name&': 'tj' }, '%26name%26=tj'); serialize({ hello: '`test`' }, 'hello=%60test%60'); serialize({ $hello: 'test' }, '$hello=test'); + serialize({ foo: 'foo', foo: 'bar' }, 'foo=foo&foo=bar'); }); });