From 96f45bf61e38e0c478fe21377f641efb24cdd240 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 22 Nov 2023 08:48:16 +0500 Subject: [PATCH] core: properly escape fts query --- packages/core/src/api/lookup.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/core/src/api/lookup.ts b/packages/core/src/api/lookup.ts index cd2d61a98..703035eda 100644 --- a/packages/core/src/api/lookup.ts +++ b/packages/core/src/api/lookup.ts @@ -42,16 +42,17 @@ export default class Lookup { notes(query: string, noteIds?: string[]) { return this.toSearchResults(async (limit) => { const db = this.db.sql() as Kysely; + query = query.replace(/"/, '""'); const result = await db .with("matching", (eb) => eb .selectFrom("content_fts") - .where("data", "match", query) + .where("data", "match", `"${query}"`) .select(["noteId as id", "rank"]) .unionAll( eb .selectFrom("notes_fts") - .where("title", "match", query) + .where("title", "match", `"${query}"`) // add 10 weight to title .select(["id", sql.raw(`rank * 10`).as("rank")]) )