Skip to content

Commit

Permalink
fix: omit queries that are set to undefined (#1486)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyeh authored and niftylettuce committed Jun 6, 2019
1 parent 30664c1 commit 7942c2d
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 7942c2d

Please sign in to comment.