From 97485beb9cecb8102c018bcb99ddb8a9710224dc Mon Sep 17 00:00:00 2001 From: medchedli Date: Wed, 28 May 2025 21:23:56 +0100 Subject: [PATCH] fix: add error handling and sanitization for URL formatting --- .../components/inbox/helpers/mapMessages.tsx | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/inbox/helpers/mapMessages.tsx b/frontend/src/components/inbox/helpers/mapMessages.tsx index adb39dcf..b23ef4ad 100644 --- a/frontend/src/components/inbox/helpers/mapMessages.tsx +++ b/frontend/src/components/inbox/helpers/mapMessages.tsx @@ -65,18 +65,25 @@ export function isSubsequent( * @description Detects URLs in text and converts them to clickable links using Autolinker */ function formatMessageText(text: string): ReactNode { - return ( - - ); + try { + const linkedText = Autolinker.link(text, { + className: "chat-link", + newWindow: true, + truncate: { length: 50, location: "middle" }, + stripPrefix: false, + sanitizeHtml: true, + }); + + return ( + + ); + } catch (error) { + return {text}; + } } /**