Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

RSS Feed: Description Field Escaping HTML Tags


Go to End


5 Posts   3082 Views

Avatar
Garrett

Community Member, 245 Posts

13 September 2011 at 7:44am

I am unable to get any of my local SilverStripe RSS feeds to display properly in any browser because the HTML tags are being escaped.

Here is the markup from RSSFeed.ss:

<description>$Description.AbsoluteLinks.EscapeXML</description>

Why is this? I can't think of any reason I would want < and > to display as &lt; and &gt; in a browser. But when I just use $Description.XML I get parsing errors. So my workaround was to use $Description.FirstParagraph(html) but then I can't figure a way to use this with AbsoluteLinks -- which I need in order for images to show up in the feed. Can someone explain to me why we are escaping tags in this template? I just want the HTML from the content to display in the feed. Why wouldn't I??

Thanks in advance,
Garrett

Avatar
Garrett

Community Member, 245 Posts

15 November 2011 at 4:25am

I ended up adding a function to strip invalid XML:

/**
	 * Return the value of the field with relative links converted to absolute urls.
	 * @return string
	 */
	function AbsoluteLinks() {
		$val = $this->StripInvalidXml($this->value);
		return HTTP::absoluteURLs($val);
	}

/**
	 * Removes invalid XML
	 *
	 * @access public
	 * @param string $value
	 * @return string
	 */
	function StripInvalidXml($value)
	{
	    $ret = "";
	    $current;
	    if (empty($value)) 
	    {
	        return $ret;
	    }
	 
	    $length = strlen($value);
	    for ($i=0; $i < $length; $i++)
	    {
	        $current = ord($value{$i});
	        if (($current == 0x9) ||
	            ($current == 0xA) ||
	            ($current == 0xD) ||
	            (($current >= 0x20) && ($current <= 0xD7FF)) ||
	            (($current >= 0xE000) && ($current <= 0xFFFD)) ||
	            (($current >= 0x10000) && ($current <= 0x10FFFF)))
	        {
	            $ret .= chr($current);
	        }
	        else
	        {
	            $ret .= " ";
	        }
	    }
	    return $ret;
	}

//Garrett

Avatar
Garrett

Community Member, 245 Posts

15 November 2011 at 4:26am

That is in sapphire/core/model/Text.php.

Avatar
phawley

Community Member, 21 Posts

12 August 2012 at 7:35am

Edited: 12/08/2012 7:36am

I am having this same problem, and just figured out a fix for it:

remove .EscapeXML in line 13 of sapphire/templates/RSSFeed.ss from :

<% if Description %><description>$Description.AbsoluteLinks.EscapeXML</description><% end_if %>

and add HTML in line 278 of sapphire/api/RSSFeed.php:

return $this->rssField($this->descriptionField, 'HTMLText');

Hopefully this helps someone else.

Avatar
tcw

Community Member, 1 Post

11 September 2012 at 6:24pm

Hey thanks @phawley this helped a lot