Reputation: 2117
In order to have a valid XML RSS feed, I need to url encode my links which contain '&' in the query string. However, when a person views the RSS feed in a browser, the links are not decoded, so when they click on the link the resulting page is broken because the query string parameters are not being read correctly.
E.g.
http://www.mysite.com?foo1=bar1&foo2=bar2, when viewed in the browser as http://www.mysite.com?foo1=bar1%26foo2=bar2, the parameter foo1 is being taken as bar1%26foo2=bar2 instead of splitting fruit and drink into two separate parameters.
Wrapping my links in tags and not encoding them work, but then in my MRSS feed I have fields such as where including a tag breaks the XML.
How can I go about correctly encoding my links so that everything works?
Upvotes: 5
Views: 3234
Reputation: 52675
Short answer
use &amp
Long answer
If you look at https://stackoverflow.com/feeds/tag/xml, the entry for this question looks like so and your sample link works fine when viewed in I.E.
Your sample link
http://www.mysite.com?foo1=bar1&foo2=bar2
Your entry
<entry>
<id>https://stackoverflow.com/questions/5705246/url-encoded-links-in-rss-breaks-links</id>
<re:rank scheme="http://stackoverflow.com">0</re:rank>
<title type="text">URL encoded links in RSS breaks links</title>
<category scheme="https://stackoverflow.com/feeds/tag/xml/tags" term="xml"/><category scheme="https://stackoverflow.com/feeds/tag/xml/tags" term="rss"/><category scheme="https://stackoverflow.com/feeds/tag/xml/tags" term="urlencode"/>
<author>
<name>Choy</name>
<uri>https://stackoverflow.com/users/252529</uri>
</author>
<link rel="alternate" href="https://stackoverflow.com/questions/5705246/url-encoded-links-in-rss-breaks-links" />
<published>2011-04-18T15:30:11Z</published>
<updated>2011-04-18T15:35:43Z</updated>
<summary type="html">
<p>In order to have a valid XML RSS feed, I need to url encode my links which contain '&amp;' in the query string. However, when a person views the RSS feed in a browser, the links are not decoded, so when they click on the link the resulting page is broken because the query string parameters are not being read correctly.</p>
<p>E.g.</p>
<p><a href="http://www.mysite.com?foo1=bar1&amp;foo2=bar2" rel="nofollow">http://www.mysite.com?foo1=bar1&amp;foo2=bar2</a>, when viewed in the browser as <a href="http://www.mysite.com?foo1=bar1%26foo2=bar2" rel="nofollow">http://www.mysite.com?foo1=bar1%26foo2=bar2</a>, the parameter foo1 is being taken as bar1%26foo2=bar2 instead of splitting fruit and drink into two separate parameters.</p>
<p>Wrapping my links in tags and not encoding them work, but then in my MRSS feed I have fields such as where including a tag breaks the XML.</p>
<p>How can I go about correctly encoding my links so that everything works?</p>
</summary>
</entry>
Upvotes: 4