fix: add error handling and sanitization for URL formatting

This commit is contained in:
medchedli 2025-05-28 21:23:56 +01:00
parent 7ac75159e1
commit 97485beb9c

View File

@ -65,18 +65,25 @@ export function isSubsequent(
* @description Detects URLs in text and converts them to clickable links using Autolinker * @description Detects URLs in text and converts them to clickable links using Autolinker
*/ */
function formatMessageText(text: string): ReactNode { function formatMessageText(text: string): ReactNode {
return ( try {
<span const linkedText = Autolinker.link(text, {
dangerouslySetInnerHTML={{ className: "chat-link",
__html: Autolinker.link(text, { newWindow: true,
className: "chat-link", truncate: { length: 50, location: "middle" },
newWindow: true, stripPrefix: false,
truncate: { length: 50, location: "middle" }, sanitizeHtml: true,
stripPrefix: false, });
}),
}} return (
/> <span
); dangerouslySetInnerHTML={{
__html: linkedText,
}}
/>
);
} catch (error) {
return <span>{text}</span>;
}
} }
/** /**