withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.8k stars 2.49k forks source link

[astro-rss] @astrojs/rss from 1.1.0 encode HTML in tags (instead of usage CDATA) and remove CDATA from customData #5677

Closed le0pard closed 11 months ago

le0pard commented 1 year ago

What version of astro are you using?

1.7.2

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

yarn

What operating system are you using?

Mac

Describe the Bug

Problem reproduced on @astrojs/rss >= 1.1.0.

  1. @astrojs/rss till version 1.1.0 use CDATA to safely define any content in description tag. But started from 1.1.0 it just using encode all tags, if they present in XML tags. This lead, that in rss content was readable as valid HTML with CDATA, now it just show in some RSS readers as encoded HTML content. Added screenshots Screenshot 2022-12-27 at 14 39 33 Screenshot 2022-12-27 at 14 40 14

  2. Any tags inside customData with CDATA converted to encoded data without CDATA inside. Example:

`<itunes:subtitle><![CDATA[${_truncate(post.frontmatter.htmlAsText(), { length: 150, omission: '...' })}]]></itunes:subtitle>`,
`<itunes:summary><![CDATA[${post.frontmatter.htmlAsText()}]]></itunes:summary>`,
`<itunes:duration>${post.frontmatter.duration}</itunes:duration>`,

Converted to result on screenshot

Screenshot 2022-12-27 at 14 43 12

Current solution is to use 1.0.3 and do not upgrade @astrojs/rss.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-jgvjth?file=src/pages/rss.xml.js

Participation

matthewp commented 1 year ago

Is this still an issue in 2.x?

le0pard commented 1 year ago

@matthewp yes, it is. Tested @astrojs/rss version 2.1.0

No CDATA, just escaped all tags

Screenshot 2023-02-08 at 21 42 35
ematipico commented 1 year ago

Will look into it

lilnasy commented 11 months ago

This seems to be intentionally disallowed by https://github.com/withastro/astro/pull/5550.

Is there a way to add the custom data you want without undoing protections introduced by that PR?

le0pard commented 11 months ago

Yep, will be cool, if will be option to escape only ]]> (need split on 2 CDATA), if it happen in content instead all html tags. But I figured myself how to fight with this (form xml myself). So I will close for now.

JaneSmith commented 1 month ago

This seems to still be an issue with 4.0.7. Can you clarify what your workaround was exactly?

le0pard commented 1 month ago

@JaneSmith as I wrote previously - I am stop using "@astrojs/rss" and just form rss myself

// src/pages/rss.xml.js
export const GET = async () => {
  const result = generateRssToString()

  return new Response(result, {
    headers: {
      'Content-Type': 'application/xml'
    }
  });
}