diff --git a/.changeset/lazy-elephants-relate.md b/.changeset/lazy-elephants-relate.md new file mode 100644 index 000000000000..7e9095dbb8eb --- /dev/null +++ b/.changeset/lazy-elephants-relate.md @@ -0,0 +1,5 @@ +--- +'@astrojs/rss': patch +--- + +Preserve self-closing tags in `customData` option diff --git a/packages/astro-rss/src/index.ts b/packages/astro-rss/src/index.ts index 35bf5f6136fd..7764b5d132c5 100644 --- a/packages/astro-rss/src/index.ts +++ b/packages/astro-rss/src/index.ts @@ -142,7 +142,13 @@ async function generateRSS(rssOptions: ValidatedRSSOptions): Promise { ? rssOptions.items : rssOptions.items.filter((item) => !item.draft); - const xmlOptions = { ignoreAttributes: false }; + const xmlOptions = { + ignoreAttributes: false, + // Avoid correcting self-closing tags to standard tags + // when using `customData` + // https://github.com/withastro/astro/issues/5794 + suppressEmptyNode: true, + }; const parser = new XMLParser(xmlOptions); const root: any = { '?xml': { '@_version': '1.0', '@_encoding': 'UTF-8' } }; if (typeof rssOptions.stylesheet === 'string') { diff --git a/packages/astro-rss/test/rss.test.js b/packages/astro-rss/test/rss.test.js index d519d19cabfa..be4362a34531 100644 --- a/packages/astro-rss/test/rss.test.js +++ b/packages/astro-rss/test/rss.test.js @@ -92,6 +92,23 @@ describe('rss', () => { chai.expect(body).xml.to.equal(validXmlWithXSLStylesheet); }); + it('should preserve self-closing tags on `customData`', async () => { + const customData = + ''; + const { body } = await rss({ + title, + description, + items: [], + site, + xmlns: { + atom: 'http://www.w3.org/2005/Atom', + }, + customData, + }); + + chai.expect(body).to.contain(customData); + }); + it('should filter out entries marked as `draft`', async () => { const { body } = await rss({ title,