0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

[RSS] Fix: Preserve self-closing tags in customData (#6538)

* fix: preserve self-closing tags in customData

* test: self-closing tags preserved

* chore: changeset
This commit is contained in:
Ben Holmes 2023-03-13 17:34:23 -04:00 committed by GitHub
parent 43daac7a9b
commit 400ef26c99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/rss': patch
---
Preserve self-closing tags in `customData` option

View file

@ -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') {

View file

@ -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,