diff --git a/lib/helpers/buildUrl.js b/lib/helpers/buildUrl.js index f624cbe50a0c3c959bcada0af4cdbbe02afdd70b..c3b6e2ff09203ec13502782e79a35fd3dba1d763 100644 --- a/lib/helpers/buildUrl.js +++ b/lib/helpers/buildUrl.js @@ -8,7 +8,9 @@ function encode(val) { replace(/%3A/gi, ':'). replace(/%24/g, '$'). replace(/%2C/gi, ','). - replace(/%20/g, '+'); + replace(/%20/g, '+'). + replace(/%5B/gi, '['). + replace(/%5D/gi, ']'); } /** @@ -29,6 +31,11 @@ module.exports = function buildUrl(url, params) { if (val === null || typeof val === 'undefined') { return; } + + if (utils.isArray(val)) { + key = key + '[]'; + } + if (!utils.isArray(val)) { val = [val]; } diff --git a/test/specs/helpers/buildUrl.spec.js b/test/specs/helpers/buildUrl.spec.js index 6bcaed03188b05276197ea7d86c43ddbc52ce319..84e58b497a69a5fdd96440a204e0f26fb0462f9a 100644 --- a/test/specs/helpers/buildUrl.spec.js +++ b/test/specs/helpers/buildUrl.spec.js @@ -30,7 +30,7 @@ describe('helpers::buildUrl', function () { it('should support array params', function () { expect(buildUrl('/foo', { foo: ['bar', 'baz'] - })).toEqual('/foo?foo=bar&foo=baz'); + })).toEqual('/foo?foo[]=bar&foo[]=baz'); }); it('should support special char params', function () {