mibe / FeedWriter

PHP Universal Feed Generator

Home Page:http://ajaxray.com/blog/php-universal-feed-generator-supports-rss-10-rss-20-and-atom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Item content special chars converted into html entities

trepmag opened this issue · comments

I'm wondering if this could be leave to the developer if he want to?...

Beside that, this produce an issue with items which are link. That is, if the link url contain ampersands in the query string part (e.g.: http://example.com/?dont=borgat&that=join&my=friend) then the output url will not corresponds.

Erm, can you give some code example? I just don't get what you mean?

Oups yes sorry my initial message doesn't contains much infos...

Feed item elements are built using htmlspecialchars():

The choice of using htmlspecialchars() could be leave to developer...

For example, this is an issue with links containing query string parts; e.g.:
$item->setLink('http://example.com/?dont=borgat&that=join&my=friend');
// The above item element content will output a non equivalent link: http://example.com/?dont=borgat&that=join&my=friend

To resolve this I've remove those htmlspecialchars() usages: trepmag@9589f10

Thank you for your explanation, I get it now.

The problem with the ampersand character is that this is a special character in the XML specification. The spec says:

The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form […]. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings "&amp;" and "&lt;" respectively.

So without htmlspecialchars() the feed would not validate properly. See the result of W3C's feed validation service here (I've encoded the ampersand in the title, otherwise the service would have stopped there).

But that encoded ampersand shouldn't actually be a problem. The client which parses the XML should turn that back into a real ampersand character. Here's a screenshot of Firefox displaying the URL with encoded ampersands.

But there is a workaround to have valid, unencoded ampersands in the link element: Wrap the link in a CDATA section. To do this call the addCDATAEncoding() method of the Feed class:

$feed->addCDATAEncoding(array('link'));

I hope that helps (and sorry I took so long to reply) 😊

Hello Mibe, this should works perfectly!

Thanks,
Cedric