Don't linkify when certain unicode formatting characters are present

This commit is contained in:
Scott Nonnenberg 2022-03-28 17:28:37 -07:00 committed by GitHub
parent e62606361d
commit 006de5b1a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 1 deletions

View file

@ -38,6 +38,26 @@ export function shouldPreviewHref(href: string): boolean {
);
}
const DIRECTIONAL_OVERRIDES = /[\u202c\u202d\u202e]/;
const UNICODE_DRAWING = /[\u2500-\u25FF]/;
export function shouldLinkifyMessage(
message: string | null | undefined
): boolean {
if (!message) {
return true;
}
if (DIRECTIONAL_OVERRIDES.test(message)) {
return false;
}
if (UNICODE_DRAWING.test(message)) {
return false;
}
return true;
}
export function isStickerPack(link = ''): boolean {
return link.startsWith('https://signal.art/addstickers/');
}
@ -47,6 +67,10 @@ export function isGroupLink(link = ''): boolean {
}
export function findLinks(text: string, caretLocation?: number): Array<string> {
if (!shouldLinkifyMessage(text)) {
return [];
}
const haveCaretLocation = isNumber(caretLocation);
const textLength = text ? text.length : 0;