From 7942c2decf44ac1f43f741dc9bbd9a63765720d1 Mon Sep 17 00:00:00 2001 From: Lee Yeh Date: Thu, 6 Jun 2019 13:49:06 +0800 Subject: [PATCH] fix: omit queries that are set to undefined (#1486) --- src/client.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/client.js b/src/client.js index 90f73f3ad..5abefe871 100644 --- a/src/client.js +++ b/src/client.js @@ -125,21 +125,23 @@ function serialize(obj) { */ function pushEncodedKeyValuePair(pairs, key, val) { - if (val !== null) { - if (Array.isArray(val)) { - val.forEach(v => { - pushEncodedKeyValuePair(pairs, key, v); - }); - } else if (isObject(val)) { - for (const subkey in val) { - if (Object.prototype.hasOwnProperty.call(val, subkey)) - pushEncodedKeyValuePair(pairs, `${key}[${subkey}]`, val[subkey]); - } - } else { - pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(val)); - } - } else if (val === null) { + if (val === undefined) return; + if (val === null) { pairs.push(encodeURIComponent(key)); + return; + } + + if (Array.isArray(val)) { + val.forEach(v => { + pushEncodedKeyValuePair(pairs, key, v); + }); + } else if (isObject(val)) { + for (const subkey in val) { + if (Object.prototype.hasOwnProperty.call(val, subkey)) + pushEncodedKeyValuePair(pairs, `${key}[${subkey}]`, val[subkey]); + } + } else { + pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(val)); } }