core: escape paranthesis in notes search query

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2025-10-27 13:00:21 +05:00
parent 36c8b8cc25
commit fca61afd7c
2 changed files with 17 additions and 1 deletions

View File

@@ -139,3 +139,18 @@ test("search reminders", () =>
const descriptionSearch = await db.lookup.reminders("please do").ids(); const descriptionSearch = await db.lookup.reminders("please do").ids();
expect(descriptionSearch).toHaveLength(1); expect(descriptionSearch).toHaveLength(1);
})); }));
describe("notesWithHighlighting", () => {
test.only("search notes with parentheses in query should load the item", () =>
noteTest({
title: "(with parantheses)"
}).then(async ({ db }) => {
await db.notes.add(TEST_NOTE);
const filtered = await db.lookup.notesWithHighlighting(
"(with parantheses)",
db.notes.all
);
const item = await filtered.item(0);
expect(item.item).toBeDefined();
}));
});

View File

@@ -1154,7 +1154,8 @@ function textContainsTokens(text: string, tokens: QueryTokens) {
const lowerCasedText = text.toLowerCase(); const lowerCasedText = text.toLowerCase();
const createTagPattern = (token: string) => { const createTagPattern = (token: string) => {
return `<${MATCH_TAG_NAME}\\s+id="(.+?)">${token}<\\/${MATCH_TAG_NAME}>`; const escapedToken = token.replace(/[()]/g, "\\$&");
return `<${MATCH_TAG_NAME}\\s+id="(.+?)">${escapedToken}<\\/${MATCH_TAG_NAME}>`;
}; };
if ( if (