Ignore punctuation when filtering rooms

Signed-off-by: Robin Townsend <robin@robin.town>
pull/21833/head
Robin Townsend 2021-03-31 22:45:53 -04:00
parent 2ab304189d
commit b13dae1fc6
1 changed files with 10 additions and 5 deletions

View File

@ -66,12 +66,17 @@ export class NameFilterCondition extends EventEmitter implements IFilterConditio
return this.matches(room.name); return this.matches(room.name);
} }
public matches(val: string): boolean { private normalize(val: string): string {
// Note: we have to match the filter with the removeHiddenChars() room name because the // Note: we have to match the filter with the removeHiddenChars() room name because the
// function strips spaces and other characters (M becomes RN for example, in lowercase). // function strips spaces and other characters (M becomes RN for example, in lowercase).
// We also doubly convert to lowercase to work around oddities of the library. return removeHiddenChars(val.toLowerCase())
const noSecretsFilter = removeHiddenChars(this.search.toLowerCase()).toLowerCase(); // Strip all punctuation
const noSecretsName = removeHiddenChars(val.toLowerCase()).toLowerCase(); .replace(/[\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~\u2000-\u206f\u2e00-\u2e7f]/g, "")
return noSecretsName.includes(noSecretsFilter); // We also doubly convert to lowercase to work around oddities of the library.
.toLowerCase();
}
public matches(val: string): boolean {
return this.normalize(val).includes(this.normalize(this.search));
} }
} }