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:
parent
43daac7a9b
commit
400ef26c99
3 changed files with 29 additions and 1 deletions
5
.changeset/lazy-elephants-relate.md
Normal file
5
.changeset/lazy-elephants-relate.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/rss': patch
|
||||
---
|
||||
|
||||
Preserve self-closing tags in `customData` option
|
|
@ -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') {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue