mirror of
https://github.com/zhigang1992/telert.git
synced 2026-04-30 20:22:25 +08:00
fix: handle null input in HTML escaping function to prevent errors
This commit is contained in:
@@ -10,7 +10,7 @@ export type RichMessage = {
|
|||||||
|
|
||||||
// https://www.30secondsofcode.org/js/s/escape-unescape-html/
|
// https://www.30secondsofcode.org/js/s/escape-unescape-html/
|
||||||
const escapeHTML = (str: string) =>
|
const escapeHTML = (str: string) =>
|
||||||
str.replace(
|
str?.replace(
|
||||||
/[&<>'"]/g,
|
/[&<>'"]/g,
|
||||||
(tag: string) =>
|
(tag: string) =>
|
||||||
({
|
({
|
||||||
@@ -20,7 +20,7 @@ const escapeHTML = (str: string) =>
|
|||||||
"'": ''',
|
"'": ''',
|
||||||
'"': '"'
|
'"': '"'
|
||||||
}[tag] || tag)
|
}[tag] || tag)
|
||||||
);
|
) ?? "";
|
||||||
|
|
||||||
export function formatRichMessage(message: RichMessage): string {
|
export function formatRichMessage(message: RichMessage): string {
|
||||||
const metadata = Object.entries(message.metadata ?? {})
|
const metadata = Object.entries(message.metadata ?? {})
|
||||||
|
|||||||
Reference in New Issue
Block a user