1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Strip direction override characters from display names (#1992)

Strip RLO and LRO characters from name and rawDisplayName so they
can safely be embedded into other text without messing up the text
ordering.

Fixes https://github.com/vector-im/element-web/issues/1712
This commit is contained in:
David Baker
2021-10-20 17:08:40 +01:00
committed by GitHub
parent d5ab4ba2ef
commit 59b3960a42
2 changed files with 28 additions and 3 deletions

View File

@@ -387,6 +387,18 @@ export function removeHiddenChars(str: string): string {
return "";
}
/**
* Removes the direction override characters from a string
* @param {string} input
* @returns string with chars removed
*/
export function removeDirectionOverrideChars(str: string): string {
if (typeof str === "string") {
return str.replace(/[\u202d-\u202e]/g, '');
}
return "";
}
export function normalize(str: string): string {
// Note: we have to match the filter with the removeHiddenChars() because the
// function strips spaces and other characters (M becomes RN for example, in lowercase).