Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSS Feed and special characters being escaped twice with cdata_wrap #100

Open
soulreverie opened this issue Apr 5, 2024 · 0 comments
Open

Comments

@soulreverie
Copy link

soulreverie commented Apr 5, 2024

<title>{{ article.name | escape_xml | cdata_wrap }}</title>

<description>{% if article.data.description != blank %}<![CDATA[{{ article.data.description }}]]>{% else %}{% if article.content[rname] != blank %}{{ article.content[rname] | select_html: css_selector: "p", limit: 1 | strip_html | escape_xml | cdata_wrap }}{% endif %}{% endif %}</description>

I ran into an issue this morning trying to deal with special characters in the RSS feed. I found that some characters were being escaped twice when using the cdata_wrap filter. An example is with a single apostrophe in article.name:

RSS Feed output:

<title><![CDATA[King to look &amp;#39;behind the curtain&amp;#39; at U.S. Supreme Court Justices&amp;#39; relationships]]></title>

Title Outputs with the &#39; because the ampersand was escaped a second time
King to look 'behind the curtain ' at U.S. Supreme Court Justices' relationships

I solved the issue for now by using inline cdata along with the filter escape_once. There might be a better answer, but for now I fixed with the following:

<title><![CDATA[{{ article.name | escape_once }}]]></title>
...
<description>{% if article.data.description != blank %}<![CDATA[{{ article.data.description | escape_once }}]]>{% else %}{% if article.content[rname] != blank %}<![CDATA[{{ article.content[rname] | select_html: css_selector: "p", limit: 1 | strip_html | escape_once }}]]>{% endif %}{% endif %}</description>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant