From c8b982fb19c95e9677d556a11de1c0c0a214dcd1 Mon Sep 17 00:00:00 2001 From: David Whittington Date: Tue, 6 Jun 2023 09:42:30 -0500 Subject: [PATCH] fix(moderation): correctly handle missing hashes when checking blocklist PE-3769 When the cache and DB are empty, we try to lookup a null hash in the blocklist. This change adjusts the SQLite DB methods to handle that case without throwing an error. --- src/database/standalone-sqlite.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/database/standalone-sqlite.ts b/src/database/standalone-sqlite.ts index c8582dd0..a2464366 100644 --- a/src/database/standalone-sqlite.ts +++ b/src/database/standalone-sqlite.ts @@ -1356,18 +1356,24 @@ export class StandaloneSqliteDatabaseWorker { return block; } - isIdBlocked(id: string): boolean { - const row = this.stmts.moderation.isIdBlocked.get({ - id: fromB64Url(id), - }); - return row?.is_blocked === 1; + isIdBlocked(id: string | undefined): boolean { + if (typeof id === 'string' && id.length > 0) { + const row = this.stmts.moderation.isIdBlocked.get({ + id: fromB64Url(id), + }); + return row?.is_blocked === 1; + } + return false } - isHashBlocked(hash: string): boolean { - const row = this.stmts.moderation.isHashBlocked.get({ - hash: fromB64Url(hash), - }); - return row?.is_blocked === 1; + isHashBlocked(hash: string | undefined): boolean { + if (typeof hash === 'string' && hash.length > 0) { + const row = this.stmts.moderation.isHashBlocked.get({ + hash: fromB64Url(hash), + }); + return row?.is_blocked === 1; + } + return false; } blockData({ @@ -1779,11 +1785,11 @@ export class StandaloneSqliteDatabase return this.queueRead('gql', 'getGqlBlock', [{ id }]); } - async isIdBlocked(id: string): Promise { + async isIdBlocked(id: string | undefined): Promise { return this.queueRead('moderation', 'isIdBlocked', [id]); } - async isHashBlocked(hash: string): Promise { + async isHashBlocked(hash: string | undefined): Promise { return this.queueRead('moderation', 'isHashBlocked', [hash]); }