Skip to content

Commit 400ef26

Browse files
authored
[RSS] Fix: Preserve self-closing tags in customData (#6538)
* fix: preserve self-closing tags in customData * test: self-closing tags preserved * chore: changeset
1 parent 43daac7 commit 400ef26

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/rss': patch
3+
---
4+
5+
Preserve self-closing tags in `customData` option

packages/astro-rss/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ async function generateRSS(rssOptions: ValidatedRSSOptions): Promise<string> {
142142
? rssOptions.items
143143
: rssOptions.items.filter((item) => !item.draft);
144144

145-
const xmlOptions = { ignoreAttributes: false };
145+
const xmlOptions = {
146+
ignoreAttributes: false,
147+
// Avoid correcting self-closing tags to standard tags
148+
// when using `customData`
149+
// https://github.com/withastro/astro/issues/5794
150+
suppressEmptyNode: true,
151+
};
146152
const parser = new XMLParser(xmlOptions);
147153
const root: any = { '?xml': { '@_version': '1.0', '@_encoding': 'UTF-8' } };
148154
if (typeof rssOptions.stylesheet === 'string') {

packages/astro-rss/test/rss.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ describe('rss', () => {
9292
chai.expect(body).xml.to.equal(validXmlWithXSLStylesheet);
9393
});
9494

95+
it('should preserve self-closing tags on `customData`', async () => {
96+
const customData =
97+
'<atom:link href="https://example.com/feed.xml" rel="self" type="application/rss+xml"/>';
98+
const { body } = await rss({
99+
title,
100+
description,
101+
items: [],
102+
site,
103+
xmlns: {
104+
atom: 'http://www.w3.org/2005/Atom',
105+
},
106+
customData,
107+
});
108+
109+
chai.expect(body).to.contain(customData);
110+
});
111+
95112
it('should filter out entries marked as `draft`', async () => {
96113
const { body } = await rss({
97114
title,

0 commit comments

Comments
 (0)