Sanitize BIDI characters from display names (#1462)

zio/stable
Paul Frazee 2023-09-15 14:05:45 -07:00 committed by GitHub
parent 763a50692f
commit 0672451ddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -6,6 +6,8 @@ import {describeModerationCause} from '../moderation'
// \u2714 = ✔ // \u2714 = ✔
// \u2611 = ☑ // \u2611 = ☑
const CHECK_MARKS_RE = /[\u2705\u2713\u2714\u2611]/gu 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( export function sanitizeDisplayName(
str: string, str: string,
@ -15,7 +17,7 @@ export function sanitizeDisplayName(
return `${describeModerationCause(moderation.cause, 'account').name}` return `${describeModerationCause(moderation.cause, 'account').name}`
} }
if (typeof str === 'string') { if (typeof str === 'string') {
return str.replace(CHECK_MARKS_RE, '').trim() return str.replace(CHECK_MARKS_RE, '').replace(CONTROL_CHARS_RE, '').trim()
} }
return '' return ''
} }