fix: handle null input in HTML escaping function to prevent errors

This commit is contained in:
Kyle Fang
2025-08-18 17:13:21 +08:00
parent 63262ca6e5
commit 2b42b5b1a6

View File

@@ -10,7 +10,7 @@ export type RichMessage = {
// https://www.30secondsofcode.org/js/s/escape-unescape-html/
const escapeHTML = (str: string) =>
str.replace(
str?.replace(
/[&<>'"]/g,
(tag: string) =>
({
@@ -20,7 +20,7 @@ const escapeHTML = (str: string) =>
"'": '&#39;',
'"': '&quot;'
}[tag] || tag)
);
) ?? "";
export function formatRichMessage(message: RichMessage): string {
const metadata = Object.entries(message.metadata ?? {})