From 7b99dc46eb25d65c1922f5b1adc5f00ac515e89f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 30 Nov 2021 18:36:18 -0500 Subject: [PATCH] test: utils.params --- public/src/utils.js | 2 +- test/utils.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/public/src/utils.js b/public/src/utils.js index 67c71d3243..8bca923287 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -662,7 +662,7 @@ if (!hash[key]) { hash[key] = value; } else { - if (!$.isArray(hash[key])) { + if (!Array.isArray(hash[key])) { hash[key] = [hash[key]]; } hash[key].push(value); diff --git a/test/utils.js b/test/utils.js index 3c13ef186c..20c0980e41 100644 --- a/test/utils.js +++ b/test/utils.js @@ -318,6 +318,14 @@ describe('Utility Methods', () => { done(); }); + it('should get url params as arrays', (done) => { + const params = utils.params({ url: 'http://nodebb.org?foo=1&bar=test&herp[]=2&herp[]=3' }); + assert.equal(params.foo, 1); + assert.equal(params.bar, 'test'); + assert.deepStrictEqual(params.herp, [2, 3]); + done(); + }); + it('should get a single param', (done) => { assert.equal(utils.param('somekey'), undefined); done();