Bug 1384168 - Handle invalid aURI in _isLocalAboutURI. r?Mardak draft
authorSamael Wang <freesamael@gmail.com>
Fri, 28 Jul 2017 18:47:35 +0800
changeset 617523 093cdebf91952ca23d2f52c56564bdfe892aceca
parent 617159 556f19ef392ac2d9aac579864e2179d6c1d464e8
child 639834 2eb67d873413105c1d3dfa1e9ad93c5d5196016d
push id71071
push userbmo:sawang@mozilla.com
push dateFri, 28 Jul 2017 15:25:46 +0000
reviewersMardak
bugs1384168
milestone56.0a1
Bug 1384168 - Handle invalid aURI in _isLocalAboutURI. r?Mardak MozReview-Commit-ID: FxZjLTZKISw
browser/base/content/tabbrowser.xml
browser/base/content/test/tabs/browser_isLocalAboutURI.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -525,26 +525,31 @@
             return false;
           }
 
           // Specially handle about:blank as local
           if (aURI.path === "blank") {
             return true;
           }
 
-          // Use the passed in resolvedURI if we have one
-          const resolvedURI = aResolvedURI || Services.io.newChannelFromURI2(
-            aURI,
-            null, // loadingNode
-            Services.scriptSecurityManager.getSystemPrincipal(), // loadingPrincipal
-            null, // triggeringPrincipal
-            Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, // securityFlags
-            Ci.nsIContentPolicy.TYPE_OTHER // contentPolicyType
-          ).URI;
-          return resolvedURI.schemeIs("jar") || resolvedURI.schemeIs("file");
+          try {
+            // Use the passed in resolvedURI if we have one
+            const resolvedURI = aResolvedURI || Services.io.newChannelFromURI2(
+              aURI,
+              null, // loadingNode
+              Services.scriptSecurityManager.getSystemPrincipal(), // loadingPrincipal
+              null, // triggeringPrincipal
+              Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL, // securityFlags
+              Ci.nsIContentPolicy.TYPE_OTHER // contentPolicyType
+            ).URI;
+            return resolvedURI.schemeIs("jar") || resolvedURI.schemeIs("file");
+          } catch (ex) {
+            // aURI might be invalid.
+            return false;
+          }
         ]]></body>
       </method>
 
       <!-- A web progress listener object definition for a given tab. -->
       <method name="mTabProgressListener">
         <parameter name="aTab"/>
         <parameter name="aBrowser"/>
         <parameter name="aStartsBlank"/>
--- a/browser/base/content/test/tabs/browser_isLocalAboutURI.js
+++ b/browser/base/content/test/tabs/browser_isLocalAboutURI.js
@@ -6,23 +6,29 @@
 /**
  * Unit tests for tabbrowser._isLocalAboutURI to make sure it returns the
  * appropriate values for various URIs as well as optional resolved URI.
  */
 
 add_task(function test_URI() {
   const check = (spec, expect, description) => {
     const URI = Services.io.newURI(spec);
-    is(gBrowser._isLocalAboutURI(URI), expect, description);
+    try {
+      is(gBrowser._isLocalAboutURI(URI), expect, description);
+    } catch (ex) {
+      ok(false, "_isLocalAboutURI should not throw");
+    }
   };
   check("https://www.mozilla.org/", false, "https is not about");
   check("http://www.mozilla.org/", false, "http is not about");
   check("about:blank", true, "about:blank is local");
   check("about:about", true, "about:about is local");
   check("about:newtab", true, "about:newtab is local");
+  check("about:random-invalid-uri", false,
+        "about:random-invalid-uri is invalid but should not throw");
 });
 
 add_task(function test_URI_with_resolved() {
   const check = (spec, resolvedSpec, expect, description) => {
     const URI = Services.io.newURI(spec);
     const resolvedURI = Services.io.newURI(resolvedSpec);
     is(gBrowser._isLocalAboutURI(URI, resolvedURI), expect, description);
   };