From f7cddd3f20e009ab8ec298d5c2ad1da01313830d Mon Sep 17 00:00:00 2001 From: Suhrid Marwah Date: Sat, 11 Apr 2026 04:32:24 +0530 Subject: [PATCH] fix(notifications): handle limit=0 in getNotifications query Replace falsy guards with explicit undefined checks so that a limit or offset of 0 is not silently discarded. Signed-off-by: Suhrid Marwah --- .../src/database/DatabaseNotificationsStore.test.ts | 5 +++++ .../src/database/DatabaseNotificationsStore.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts index d8ae3faf57..429aea4f3d 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts @@ -469,6 +469,11 @@ describe.each(databases.eachSupportedId())( id3, ]); }); + + it('should return empty array when limit is 0', async () => { + const result = await storage.getNotifications({ user, limit: 0 }); + expect(result).toEqual([]); + }); }); describe('getNotifications sorting', () => { diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts index 5bed0c7674..6ebd64f4f4 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts @@ -289,11 +289,11 @@ export class DatabaseNotificationsStore implements NotificationsStore { } } - if (options.limit) { + if (options.limit !== undefined) { query.limit(options.limit); } - if (options.offset) { + if (options.offset !== undefined) { query.offset(options.offset); }