mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 00:56:13 +01:00
fix: closes #11343, don't crash if tags array is empty
This commit is contained in:
@@ -26,7 +26,7 @@ module.exports = function (module) {
|
|||||||
|
|
||||||
async function getSortedSetUnion(params) {
|
async function getSortedSetUnion(params) {
|
||||||
if (!Array.isArray(params.sets) || !params.sets.length) {
|
if (!Array.isArray(params.sets) || !params.sets.length) {
|
||||||
return;
|
return [];
|
||||||
}
|
}
|
||||||
let limit = params.stop - params.start + 1;
|
let limit = params.stop - params.start + 1;
|
||||||
if (limit <= 0) {
|
if (limit <= 0) {
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ SELECT COUNT(DISTINCT z."value") c
|
|||||||
|
|
||||||
async function getSortedSetUnion(params) {
|
async function getSortedSetUnion(params) {
|
||||||
const { sets } = params;
|
const { sets } = params;
|
||||||
|
if (!sets || !sets.length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
const start = params.hasOwnProperty('start') ? params.start : 0;
|
const start = params.hasOwnProperty('start') ? params.start : 0;
|
||||||
const stop = params.hasOwnProperty('stop') ? params.stop : -1;
|
const stop = params.hasOwnProperty('stop') ? params.stop : -1;
|
||||||
let weights = params.weights || [];
|
let weights = params.weights || [];
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ module.exports = function (Topics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Topics.getTagData = async function (tags) {
|
Topics.getTagData = async function (tags) {
|
||||||
if (!tags.length) {
|
if (!tags || !tags.length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
tags.forEach((tag) => {
|
tags.forEach((tag) => {
|
||||||
|
|||||||
@@ -996,6 +996,11 @@ describe('Sorted Set methods', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return empty array if sets is empty', async () => {
|
||||||
|
const result = await db.getSortedSetRevUnion({ sets: [], start: 0, stop: -1 });
|
||||||
|
assert.deepStrictEqual(result, []);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sortedSetIncrBy()', () => {
|
describe('sortedSetIncrBy()', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user