Bug 541718 - Check that a non-permalink guid is a valid url before using it as a url; r=myk
--- a/mailnews/extensions/newsblog/content/feed-parser.js
+++ b/mailnews/extensions/newsblog/content/feed-parser.js
@@ -34,16 +34,17 @@
* the terms of any one of the MPL, the GPL or the
* ***** END LICENSE BLOCK ***** */
// The feed parser depends on FeedItems.js, Feed.js.
var rdfcontainer = Components.classes["@mozilla.org/rdf/container-utils;1"].getService(Components.interfaces.nsIRDFContainerUtils);
var rdfparser = Components.classes["@mozilla.org/rdf/xml-parser;1"].createInstance(Components.interfaces.nsIRDFXMLParser);
var serializer = Components.classes["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(Components.interfaces.nsIDOMSerializer);
+var gIOService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
function FeedParser()
{}
FeedParser.prototype =
{
// parseFeed returns an array of parsed items ready for processing
// it is currently a synchronous operation. If there was an error parsing the feed,
@@ -134,16 +135,31 @@ FeedParser.prototype =
{
guid = getNodeValue(guidNode);
// isPermaLink is true if the value is "true" or if the attribute is
// not present; all other values, including "false" and "False" and
// for that matter "TRuE" and "meatcake" are false.
if (!guidNode.hasAttribute("isPermaLink") ||
guidNode.getAttribute("isPermaLink") == "true")
isPermaLink = true;
+ // if attribute isPermaLink is missing, it is good to check the validity
+ // of <guid> value as an URL to avoid linking to non-URL strings
+ if (!guidNode.hasAttribute("isPermaLink"))
+ {
+ try
+ {
+ gIOService.newURI(guid, null, null);
+ if (gIOService.extractScheme(guid) == "tag")
+ isPermaLink = false;
+ }
+ catch (ex)
+ {
+ isPermaLink = false;
+ }
+ }
item.id = guid;
item.isStoredWithId = true;
}
item.url = (guid && isPermaLink) ? guid : link ? link : null;
item.description = getNodeValue(this.childrenByTagNameNS(itemNode, nsURI, "description")[0]);
item.title = getNodeValue(this.childrenByTagNameNS(itemNode, nsURI, "title")[0])