From 06d8370fe63b171fd5efbf6a62187f7e5d977d1c Mon Sep 17 00:00:00 2001 From: Ahmad Dakhlallah Date: Fri, 5 May 2023 17:51:33 +0300 Subject: [PATCH 1/2] Enhance RTL detection by ignoring links in post --- app/soapbox/rtl.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/soapbox/rtl.ts b/app/soapbox/rtl.ts index 4c3599cb6..f069bf5c4 100644 --- a/app/soapbox/rtl.ts +++ b/app/soapbox/rtl.ts @@ -19,7 +19,12 @@ export function isRtl(text: string): boolean { if (text.length === 0) { return false; } - + // Remove http(s), (s)ftp, ws(s), blob and smtp(s) links + text = text.replace(/(?:https?|ftp|sftp|ws|wss|blob|smtp|smtps):\/\/[\n\S]+/g, ''); + // Remove email address links + text = text.replace(/(mailto:)([^\s@]+@[^\s@]+\.[^\s@]+)/g, ''); + // Remove Phone numbe links + text = text.replace(/(tel:)([+\d\s()-]+)/g, ''); text = text.replace(/(?:^|[^\/\w])@([a-z0-9_]+(@[a-z0-9\.\-]+)?)/ig, ''); text = text.replace(/(?:^|[^\/\w])#([\S]+)/ig, ''); text = text.replace(/\s+/g, ''); @@ -27,6 +32,7 @@ export function isRtl(text: string): boolean { const matches = text.match(rtlChars); if (!matches) { + return false; } From 7a0ce1aab4e951960517148f70e3647a7e42fd60 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 5 May 2023 16:26:58 +0000 Subject: [PATCH 2/2] Sound better now! --- app/soapbox/rtl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/rtl.ts b/app/soapbox/rtl.ts index f069bf5c4..16a6100ef 100644 --- a/app/soapbox/rtl.ts +++ b/app/soapbox/rtl.ts @@ -20,7 +20,7 @@ export function isRtl(text: string): boolean { return false; } // Remove http(s), (s)ftp, ws(s), blob and smtp(s) links - text = text.replace(/(?:https?|ftp|sftp|ws|wss|blob|smtp|smtps):\/\/[\n\S]+/g, ''); + text = text.replace(/(?:https?|ftp|sftp|ws|wss|blob|smtp|smtps):\/\/[\S]+/g, ''); // Remove email address links text = text.replace(/(mailto:)([^\s@]+@[^\s@]+\.[^\s@]+)/g, ''); // Remove Phone numbe links