Skip to content

Commit

Permalink
Desktop: Fixes #9775: Fix search when note or OCR text contains null …
Browse files Browse the repository at this point in the history
…characters (#9774)
  • Loading branch information
personalizedrefrigerator authored Jan 25, 2024
1 parent 938e639 commit c4ff785
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/lib/services/search/SearchEngine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ describe('services/SearchEngine', () => {
expect(rows[2].id).toBe(n3.id);
}));

it('should support searching through documents that contain null characters', (async () => {
await Note.save({ title: 'Test', body: 'Test\x00testing' });

await engine.syncTables();

expect((await engine.search('testing')).length).toBe(1);
}));

it('should supports various query types', (async () => {
let rows;

Expand Down
7 changes: 6 additions & 1 deletion packages/lib/services/search/SearchEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,12 @@ export default class SearchEngine {
}

private normalizeText_(text: string) {
const normalizedText = text.normalize ? text.normalize() : text;
let normalizedText = text.normalize ? text.normalize() : text;

// Null characters can break FTS. Remove them.
// eslint-disable-next-line no-control-regex
normalizedText = normalizedText.replace(/\x00/g, ' ');

return removeDiacritics(normalizedText.toLowerCase());
}

Expand Down

0 comments on commit c4ff785

Please sign in to comment.