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():
- https://github.com/mibe/FeedWriter/blob/master/Feed.php#L730
- https://github.com/mibe/FeedWriter/blob/master/Feed.php#L749
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 "&" and "<" 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