Bug 1384168 - Handle invalid aURI in _isLocalAboutURI. r=Mardak
authorSamael Wang <freesamael@gmail.com>
Fri, 28 Jul 2017 18:47:35 +0800
changeset 420363 e2c06426fc2e1340ca316a03653408452a16f960
parent 420362 dc11f189ddea676216f9ddaeb0f2cfdae9b08718
child 420364 2948f11c75c809caff4491384d68698608c4f59a
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMardak
bugs1384168
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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);
   };