From cc751e0287f70366c12bd7351079fb1a291dde9b Mon Sep 17 00:00:00 2001 From: Gbubemi Smith Date: Tue, 24 May 2022 23:40:17 +0100 Subject: [PATCH] [PS-136] stripped off accented characters from search field for browser client (#812) * stripped off accented characters from search field for browser client * moved normalization from component to search service * fixed conflicts * removed normalization from cipher component * added comments to normalize method * added comments to normalize method --- common/src/services/search.service.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/common/src/services/search.service.ts b/common/src/services/search.service.ts index 92e54fad6ab..cb44a59b48e 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, ""); + } }