From 7353820456c874b308daf55853a45d53c1ae0c0e Mon Sep 17 00:00:00 2001 From: Tin Date: Tue, 9 May 2017 18:06:05 -0700 Subject: [PATCH] fix: do not return empty query for empty array --- encode.js | 2 +- test/index.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/encode.js b/encode.js index 76e4cfb..01bdd63 100644 --- a/encode.js +++ b/encode.js @@ -54,7 +54,7 @@ module.exports = function(obj, sep, eq, name) { } else { return ks + encodeURIComponent(stringifyPrimitive(obj[k])); } - }).join(sep); + }).filter(function(q) {return q !== '';}).join(sep); } diff --git a/test/index.js b/test/index.js index 62eb2ac..9edd7eb 100644 --- a/test/index.js +++ b/test/index.js @@ -164,6 +164,9 @@ exports['test stringifying'] = function(assert) { assert.equal(testCase[1], qs.stringify(testCase[0]), 'stringify ' + JSON.stringify(testCase[0])); }); + + assert.equal(qs.stringify({filter:[], x:1}), 'x=1', 'stringify should not include empty array'); + assert.equal(qs.stringify({filter:[]}), '', 'stringify should not include empty array'); }; exports['test stringifying nested'] = function(assert) {