diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index a3ae9c49..372ed2b3 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -7,6 +7,14 @@ import sanitizeHtml from "sanitize-html"; const parser = new MarkdownIt(); +function stripInvalidXmlChars(str: string): string { + return str.replace( + // biome-ignore lint/suspicious/noControlCharactersInRegex: https://www.w3.org/TR/xml/#charsets + /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFDD0-\uFDEF\uFFFE\uFFFF]/g, + "", + ); +} + export async function GET(context: APIContext) { const blog = await getSortedPosts(); @@ -17,13 +25,13 @@ export async function GET(context: APIContext) { items: blog.map((post) => { const content = typeof post.body === "string" ? post.body : String(post.body || ""); - + const cleanedContent = stripInvalidXmlChars(content); return { title: post.data.title, pubDate: post.data.published, description: post.data.description || "", link: `/posts/${post.slug}/`, - content: sanitizeHtml(parser.render(content), { + content: sanitizeHtml(parser.render(cleanedContent), { allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]), }), };