Bug: Double-encoded HTML entities in item `<title>` (`&#8217;` becomes `&amp;#8217;`)

Bug: Double-encoded HTML entities in item <title> (&#8217; becomes &amp;#8217;)

Description

When source feeds (such as The Verge or WordPress-based RSS feeds) contain numeric HTML character references in their titles (e.g. curly apostrophes or quotes like &#8217; inside a CDATA block), the generated Full-Text RSS output double-encodes the ampersand:

<!-- Source Feed: -->
<title type="html"><![CDATA[Intel says it&#8217;s selling every affordable laptop chip it can make]]></title>

<!-- Full-Text RSS Output: -->
<title>Intel says it&amp;#8217;s selling every affordable laptop chip it can make</title>

As a result, RSS readers (such as FreshRSS, Miniflux, and NetNewsWire) parse &amp; back into a literal & and display the raw code it&#8217;s instead of the apostrophe (it’s).


Root Cause

In makefulltextfeed.php (around line 712):

$feed_item_title = strip_tags(htmlspecialchars_decode($feed_item_title));

PHP’s htmlspecialchars_decode() only converts &amp;, &quot;, &#039;, &lt;, and &gt;. It does not decode numeric character entities such as &#8217; or &#8220;.

Because &#8217; remains as literal text in $feed_item_title, the XML FeedWriter later escapes the ampersand into &amp;, producing &amp;#8217;.


Suggested Fix

Replace htmlspecialchars_decode() with html_entity_decode() so numeric and named HTML entities are converted to UTF-8 characters prior to XML generation:

$feed_item_title = strip_tags(html_entity_decode($feed_item_title, ENT_QUOTES, 'UTF-8'));

Welcome @Javedalidev

I’m not a developer, but that sounds reasonable to me. Could you please add some example URLs of those articles, so @fivefilters could have a look on it?

Here are few example:

Few more:

Hi @Javedalidev I’ve tested your links an the feed URL https://www.theverge.com/rss/index.xml

and I could not see your reported problem, neither on the FulltextRSS preview page nor on FreshRSS. And the FTR-premium site also has no errors with apostrophes or quotation marks.

Which version of FulltextRSS are you using? I am on 3.9.13

Which is the PHP version you are running this? I am on 8.1.34

post the output of yourftrserver.local/ftr_compatibility_test.php

I am not a developer and I am not a staff member of fivefilters but I bet your PHP version might be too new or too old - or one of the php modules is missing.

Yeah, got the issue. I’m using a custom Docker image, and it uses the Old PHP version.
Thank you so much for looking into this. Very well appreciated.

1 Like