mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-22 11:45:59 +01:00
[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
This commit is contained in:
parent
0a072b6452
commit
cc751e0287
@ -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<CipherView[]> {
|
||||
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, "");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user