Merge pull request #8857 from 01zulfi/core/escape-paranthesis-in-search

core: escape paranthesis in notes search query
This commit is contained in:
Abdullah Atta
2025-11-03 12:37:39 +05:00
committed by GitHub
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();
expect(descriptionSearch).toHaveLength(1);
}));
describe("notesWithHighlighting", () => {
test("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 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 (