diff --git a/CliClient/tests/services_SearchEngine.js b/CliClient/tests/services_SearchEngine.js index 37748d6e7..0b8e4c8b2 100644 --- a/CliClient/tests/services_SearchEngine.js +++ b/CliClient/tests/services_SearchEngine.js @@ -254,4 +254,26 @@ describe('services_SearchEngine', function() { expect(engine.parseQuery('*').termCount).toBe(0); })); + it('should handle queries with special characters', asyncTest(async () => { + let rows; + + const testCases = [ + ['did-not-match', 'did-not-match'], + ['does match', 'does match'], + ]; + + for (let i = 0; i < testCases.length; i++) { + const t = testCases[i]; + const content = t[0]; + const query = t[1]; + + const n = await Note.save({ title: content }); + await engine.syncTables(); + rows = await engine.search(query); + expect(rows.length).toBe(1); + + await Note.delete(n.id); + } + })); + }); \ No newline at end of file diff --git a/ReactNativeClient/lib/services/SearchEngine.js b/ReactNativeClient/lib/services/SearchEngine.js index 15a79dd1b..ad4b53c85 100644 --- a/ReactNativeClient/lib/services/SearchEngine.js +++ b/ReactNativeClient/lib/services/SearchEngine.js @@ -355,6 +355,7 @@ class SearchEngine { async search(query) { query = this.normalizeText_(query); + query = query.replace(/-/g, ' '); // https://github.com/laurent22/joplin/issues/1075#issuecomment-459258856 const st = scriptType(query);