fix: telegram html arsing failure

This commit is contained in:
wonfen 2026-03-21 22:28:27 +08:00
parent 520a7ed83f
commit fc086eeab2
No known key found for this signature in database
GPG Key ID: CEAFD6C73AB2001F

View File

@ -82,8 +82,26 @@ async function sendTelegramNotification() {
.replace(/<br\s*\/?>/g, '\n')
}
// Strip HTML tags not supported by Telegram and escape stray angle brackets
function sanitizeTelegramHTML(content) {
// Telegram supports: b, strong, i, em, u, ins, s, strike, del,
// a, code, pre, blockquote, tg-spoiler, tg-emoji
const allowedTags =
/^\/?(b|strong|i|em|u|ins|s|strike|del|a|code|pre|blockquote|tg-spoiler|tg-emoji)(\s|>|$)/i
return content.replace(/<\/?[^>]*>/g, (tag) => {
const inner = tag.replace(/^<\/?/, '').replace(/>$/, '')
if (allowedTags.test(inner) || allowedTags.test(tag.slice(1))) {
return tag
}
// Escape unsupported tags so they display as text
return tag.replace(/</g, '&lt;').replace(/>/g, '&gt;')
})
}
releaseContent = normalizeDetailsTags(releaseContent)
const formattedContent = convertMarkdownToTelegramHTML(releaseContent)
const formattedContent = sanitizeTelegramHTML(
convertMarkdownToTelegramHTML(releaseContent),
)
const releaseTitle = isAutobuild ? '滚动更新版发布' : '正式发布'
const encodedVersion = encodeURIComponent(version)