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
|
* @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>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user