From 0b449347c1f9b1aea49ec79d4cbb9f16440ced2e Mon Sep 17 00:00:00 2001 From: Mononaut Date: Sun, 26 Nov 2023 09:22:44 +0000 Subject: [PATCH] Fix spurious ln channel typeahead matches --- backend/src/api/explorer/channels.api.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/src/api/explorer/channels.api.ts b/backend/src/api/explorer/channels.api.ts index 0b1b914fd..cf38610b4 100644 --- a/backend/src/api/explorer/channels.api.ts +++ b/backend/src/api/explorer/channels.api.ts @@ -80,7 +80,13 @@ class ChannelsApi { public async $searchChannelsById(search: string): Promise { try { - const searchStripped = search.replace(/[^0-9x]/g, '') + '%'; + // restrict search to valid id/short_id prefix formats + let searchStripped = search.match(/[0-9]+[0-9x]*/)?.[0] || ''; + if (!searchStripped.length) { + return []; + } + // add wildcard to search by prefix + searchStripped += '%'; const query = `SELECT id, short_id, capacity, status FROM channels WHERE id LIKE ? OR short_id LIKE ? LIMIT 10`; const [rows]: any = await DB.query(query, [searchStripped, searchStripped]); return rows;