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={{
__html: Autolinker.link(text, {
className: "chat-link", className: "chat-link",
newWindow: true, newWindow: true,
truncate: { length: 50, location: "middle" }, truncate: { length: 50, location: "middle" },
stripPrefix: false, stripPrefix: false,
}), sanitizeHtml: true,
});
return (
<span
dangerouslySetInnerHTML={{
__html: linkedText,
}} }}
/> />
); );
} catch (error) {
return <span>{text}</span>;
}
} }
/** /**