Skip to content

Commit

Permalink
fix: closes #11343, don't crash if tags array is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Mar 10, 2023
1 parent c03d5db commit 56427e4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/database/mongo/sorted/union.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function (module) {

async function getSortedSetUnion(params) {
if (!Array.isArray(params.sets) || !params.sets.length) {
return;
return [];
}
let limit = params.stop - params.start + 1;
if (limit <= 0) {
Expand Down
3 changes: 3 additions & 0 deletions src/database/postgres/sorted/union.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ SELECT COUNT(DISTINCT z."value") c

async function getSortedSetUnion(params) {
const { sets } = params;
if (!sets || !sets.length) {
return [];
}
const start = params.hasOwnProperty('start') ? params.start : 0;
const stop = params.hasOwnProperty('stop') ? params.stop : -1;
let weights = params.weights || [];
Expand Down
2 changes: 1 addition & 1 deletion src/topics/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ module.exports = function (Topics) {
}

Topics.getTagData = async function (tags) {
if (!tags.length) {
if (!tags || !tags.length) {
return [];
}
tags.forEach((tag) => {
Expand Down
5 changes: 5 additions & 0 deletions test/database/sorted.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,11 @@ describe('Sorted Set methods', () => {
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()', () => {
Expand Down

0 comments on commit 56427e4

Please sign in to comment.