Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
[PS-136] stripped off accented characters from search field for brows…
Browse files Browse the repository at this point in the history
…er 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
  • Loading branch information
gbubemismith committed May 24, 2022
1 parent 0a072b6 commit cc751e0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions common/src/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down Expand Up @@ -97,7 +98,7 @@ export class SearchService implements SearchServiceAbstraction {
): Promise<CipherView[]> {
const results: CipherView[] = [];
if (query != null) {
query = query.trim().toLowerCase();
query = this.normalizeSearchQuery(query.trim().toLowerCase());
}
if (query === "") {
query = null;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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, "");
}
}

0 comments on commit cc751e0

Please sign in to comment.