Bug 1157503 - NewTabUtils.extractSite should try-catch nsIURI.asciiHost. r=ttaubert,Mardak, a=lizzard
authorDrew Willcoxon <adw@mozilla.com>
Thu, 23 Apr 2015 15:52:16 -0700
changeset 267369 728c8bbc58434cf0b5ce48ec128e69d556e4decb
parent 267368 069da5c02e22aeacfb758d3ab6fedcb9dd781bd2
child 267370 b7fd790b9f598f7865172e2b1d9835141f6c38c3
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert, Mardak, lizzard
bugs1157503
milestone39.0a2
Bug 1157503 - NewTabUtils.extractSite should try-catch nsIURI.asciiHost. r=ttaubert,Mardak, a=lizzard
toolkit/modules/NewTabUtils.jsm
--- a/toolkit/modules/NewTabUtils.jsm
+++ b/toolkit/modules/NewTabUtils.jsm
@@ -1306,25 +1306,27 @@ this.NewTabUtils = {
 
   /**
    * Extract a "site" from a url in a way that multiple urls of a "site" returns
    * the same "site."
    * @param aUrl Url spec string
    * @return The "site" string or null
    */
   extractSite: function Links_extractSite(url) {
-    let uri;
+    let host;
     try {
-      uri = Services.io.newURI(url, null, null);
+      // Note that nsIURI.asciiHost throws NS_ERROR_FAILURE for some types of
+      // URIs, including jar and moz-icon URIs.
+      host = Services.io.newURI(url, null, null).asciiHost;
     } catch (ex) {
       return null;
     }
 
     // Strip off common subdomains of the same site (e.g., www, load balancer)
-    return uri.asciiHost.replace(/^(m|mobile|www\d*)\./, "");
+    return host.replace(/^(m|mobile|www\d*)\./, "");
   },
 
   init: function NewTabUtils_init() {
     if (this.initWithoutProviders()) {
       PlacesProvider.init();
       Links.addProvider(PlacesProvider);
       BlockedLinks.addObserver(Links);
     }