Skip to content

Commit

Permalink
Merge pull request #1808 from MaoShizhong/fix/unify-body-query-serial…
Browse files Browse the repository at this point in the history
…isation-behaviour

fix: unify body and query serialisation behaviour
  • Loading branch information
titanism committed Aug 24, 2024
2 parents 072d898 + bef7b08 commit bfb2d00
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
4 changes: 3 additions & 1 deletion src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
1 change: 1 addition & 0 deletions test/client/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Check failure on line 41 in test/client/serialize.js

View workflow job for this annotation

GitHub Actions / test (16.x)

Duplicate key 'foo'
});
});

Expand Down

0 comments on commit bfb2d00

Please sign in to comment.