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) {