Skip to content

Node.js based forum software built for the modern web

test: utils.params

Barış Soner Uşaklı7b99dc46eb25
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();