A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: escape paranthesis in notes search query Signed-off-by: 01zulfi <[email protected]>
01zulfifca61afd7cb3
diff --git a/packages/core/__tests__/lookup.test.js b/packages/core/__tests__/lookup.test.jsindex 018c6f088..5d4b6d239 100644--- a/packages/core/__tests__/lookup.test.js+++ b/packages/core/__tests__/lookup.test.js@@ -139,3 +139,18 @@ test("search reminders", () =>const descriptionSearch = await db.lookup.reminders("please do").ids();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();+ }));+});diff --git a/packages/core/src/api/lookup.ts b/packages/core/src/api/lookup.tsindex 8cdab505a..46234a097 100644--- a/packages/core/src/api/lookup.ts+++ b/packages/core/src/api/lookup.ts@@ -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 (