Bug 541718 - Check that a non-permalink guid is a valid url before using it as a url; r=myk
authorFosfor <fosfor.software@seznam.cz>
Thu, 18 Nov 2010 13:36:58 +0000
changeset 6711 9bf1ef38cc60d4fcff5b634e3199877829e137ab
parent 6710 bbf09f7bab5c2dccb0032d094b78c3e66359d8f1
child 6712 9a268939f29cbb223900a3d73b770e0b60e5143b
push idunknown
push userunknown
push dateunknown
reviewersmyk
bugs541718
Bug 541718 - Check that a non-permalink guid is a valid url before using it as a url; r=myk
mailnews/extensions/newsblog/content/feed-parser.js
--- 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])