Skip to content

Commit

Permalink
[RSS] Fix: Preserve self-closing tags in customData (#6538)
Browse files Browse the repository at this point in the history
* fix: preserve self-closing tags in customData

* test: self-closing tags preserved

* chore: changeset
  • Loading branch information
bholmesdev authored Mar 13, 2023
1 parent 43daac7 commit 400ef26
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/lazy-elephants-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/rss': patch
---

Preserve self-closing tags in `customData` option
8 changes: 7 additions & 1 deletion packages/astro-rss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ async function generateRSS(rssOptions: ValidatedRSSOptions): Promise<string> {
? 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') {
Expand Down
17 changes: 17 additions & 0 deletions packages/astro-rss/test/rss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ describe('rss', () => {
chai.expect(body).xml.to.equal(validXmlWithXSLStylesheet);
});

it('should preserve self-closing tags on `customData`', async () => {
const customData =
'<atom:link href="https://example.com/feed.xml" rel="self" type="application/rss+xml"/>';
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,
Expand Down

0 comments on commit 400ef26

Please sign in to comment.