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