From 7a3d30a92c608e9a1a4340163bf1bdbeef9f0f5b Mon Sep 17 00:00:00 2001 From: John Ferlito Date: Tue, 21 Jan 2020 13:38:42 +1100 Subject: [PATCH] Fix URI encoding According to HTTP spec keys should be encoded slightly differently to values. --- src/client.js | 4 ++-- test/client/serialize.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client.js b/src/client.js index 209912e12..419f225aa 100644 --- a/src/client.js +++ b/src/client.js @@ -128,7 +128,7 @@ function serialize(obj) { function pushEncodedKeyValuePair(pairs, key, val) { if (val === undefined) return; if (val === null) { - pairs.push(encodeURIComponent(key)); + pairs.push(encodeURI(key)); return; } @@ -142,7 +142,7 @@ function pushEncodedKeyValuePair(pairs, key, val) { pushEncodedKeyValuePair(pairs, `${key}[${subkey}]`, val[subkey]); } } else { - pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(val)); + pairs.push(encodeURI(key) + '=' + encodeURIComponent(val)); } } diff --git a/test/client/serialize.js b/test/client/serialize.js index 77e8f9e8b..831287cfd 100644 --- a/test/client/serialize.js +++ b/test/client/serialize.js @@ -35,6 +35,7 @@ describe('request.serializeObject()', () => { serialize({ name: '&tj&' }, 'name=%26tj%26'); serialize({ '&name&': 'tj' }, '%26name%26=tj'); serialize({ hello: '`test`' }, 'hello=%60test%60'); + serialize({ $hello: 'test' }, '$hello=test'); }); });