Sanitize BIDI characters from display names (#1462)
parent
763a50692f
commit
0672451ddc
|
@ -6,6 +6,8 @@ import {describeModerationCause} from '../moderation'
|
|||
// \u2714 = ✔
|
||||
// \u2611 = ☑
|
||||
const CHECK_MARKS_RE = /[\u2705\u2713\u2714\u2611]/gu
|
||||
const CONTROL_CHARS_RE =
|
||||
/[\u0000-\u001F\u007F-\u009F\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g
|
||||
|
||||
export function sanitizeDisplayName(
|
||||
str: string,
|
||||
|
@ -15,7 +17,7 @@ export function sanitizeDisplayName(
|
|||
return `⚠${describeModerationCause(moderation.cause, 'account').name}`
|
||||
}
|
||||
if (typeof str === 'string') {
|
||||
return str.replace(CHECK_MARKS_RE, '').trim()
|
||||
return str.replace(CHECK_MARKS_RE, '').replace(CONTROL_CHARS_RE, '').trim()
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue