diff --git a/common/src/services/search.service.ts b/common/src/services/search.service.ts index 92e54fad6a..cb44a59b48 100644 --- a/common/src/services/search.service.ts +++ b/common/src/services/search.service.ts @@ -34,6 +34,7 @@ export class SearchService implements SearchServiceAbstraction { } isSearchable(query: string): boolean { + query = this.normalizeSearchQuery(query); const notSearchable = query == null || (this.index == null && query.length < this.searchableMinLength) || @@ -97,7 +98,7 @@ export class SearchService implements SearchServiceAbstraction { ): Promise { const results: CipherView[] = []; if (query != null) { - query = query.trim().toLowerCase(); + query = this.normalizeSearchQuery(query.trim().toLowerCase()); } if (query === "") { query = null; @@ -165,7 +166,7 @@ export class SearchService implements SearchServiceAbstraction { } searchCiphersBasic(ciphers: CipherView[], query: string, deleted = false) { - query = query.trim().toLowerCase(); + query = this.normalizeSearchQuery(query.trim().toLowerCase()); return ciphers.filter((c) => { if (deleted !== c.isDeleted) { return false; @@ -187,7 +188,7 @@ export class SearchService implements SearchServiceAbstraction { } searchSends(sends: SendView[], query: string) { - query = query.trim().toLocaleLowerCase(); + query = this.normalizeSearchQuery(query.trim().toLocaleLowerCase()); if (query === null) { return sends; } @@ -294,12 +295,14 @@ export class SearchService implements SearchServiceAbstraction { const checkFields = fields.every((i: any) => searchableFields.includes(i)); if (checkFields) { - return token - .toString() - .normalize("NFD") - .replace(/[\u0300-\u036f]/g, ""); + return this.normalizeSearchQuery(token.toString()); } return token; } + + // Remove accents/diacritics characters from text. This regex is equivalent to the Diacritic unicode property escape, i.e. it will match all diacritic characters. + private normalizeSearchQuery(query: string): string { + return query?.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); + } }