From b8ec9362472e77353ac68508fa3fb3bac40cbe72 Mon Sep 17 00:00:00 2001 From: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com> Date: Sat, 29 Jun 2024 01:23:34 +0100 Subject: [PATCH 1/2] fix: unify urlencoded body serialisation with current query serialisation Body serialisation now also matches documentation. --- src/client.js | 4 +++- src/node/index.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 75217c8bd..54806ab94 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -98,7 +98,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 }; From bef7b08b14ab8088a1146e544902fa633b5568bd Mon Sep 17 00:00:00 2001 From: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com> Date: Sat, 29 Jun 2024 01:44:35 +0100 Subject: [PATCH 2/2] test: add test for serialising duplicated keys --- test/client/serialize.js | 1 + 1 file changed, 1 insertion(+) 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'); }); });