mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: add error handling and sanitization for URL formatting
This commit is contained in:
parent
7ac75159e1
commit
97485beb9c
@ -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>;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user