Bug 989197 - Use URLSearchParams instead of regex to parse params in about:net/certerror URLs. r=Gijs
authorNihanth Subramanya <nhnt11@gmail.com>
Tue, 06 Dec 2016 10:25:53 -1000
changeset 448571 b60d8554e94f9190bf98a1ba5e40a35b376f3431
parent 448570 c51e7406d7b2e2246a1ece0d8989282ca752039f
child 448572 7c05b704b149db83ee21756bfdda1994d587e08e
push id38361
push usernhnt11@gmail.com
push dateSat, 10 Dec 2016 21:36:44 +0000
reviewersGijs
bugs989197
milestone53.0a1
Bug 989197 - Use URLSearchParams instead of regex to parse params in about:net/certerror URLs. r=Gijs MozReview-Commit-ID: KKK2pL2bcwU
browser/base/content/aboutNetError.xhtml
--- a/browser/base/content/aboutNetError.xhtml
+++ b/browser/base/content/aboutNetError.xhtml
@@ -21,64 +21,45 @@
   <head>
     <title>&loadError.label;</title>
     <link rel="stylesheet" href="chrome://browser/skin/aboutNetError.css" type="text/css" media="all" />
     <!-- If the location of the favicon is changed here, the FAVICON_ERRORPAGE_URL symbol in
          toolkit/components/places/src/nsFaviconService.h should be updated. -->
     <link rel="icon" type="image/png" id="favicon" href="chrome://global/skin/icons/warning-16.png"/>
 
     <script type="application/javascript"><![CDATA[
-      // Error url MUST be formatted like this:
-      //   moz-neterror:page?e=error&u=url&d=desc
-      //
-      // or optionally, to specify an alternate CSS class to allow for
-      // custom styling and favicon:
-      //
-      //   moz-neterror:page?e=error&u=url&s=classname&d=desc
+      // The following parameters are parsed from the error URL:
+      //   e - the error code
+      //   s - custom CSS class to allow alternate styling/favicons
+      //   d - error description
 
       // Note that this file uses document.documentURI to get
       // the URL (with the format from above). This is because
       // document.location.href gets the current URI off the docshell,
       // which is the URL displayed in the location bar, i.e.
       // the URI that the user attempted to load.
 
+      let searchParams = new URLSearchParams(document.documentURI.split("?")[1]);
+
+      // Set to true on init if the error code is nssBadCert.
+      let gIsCertError;
+
       function getErrorCode()
       {
-        var url = document.documentURI;
-        var error = url.search(/e\=/);
-        var duffUrl = url.search(/\&u\=/);
-        return decodeURIComponent(url.slice(error + 2, duffUrl));
+        return searchParams.get("e");
       }
 
-      // Set to true on init if the error code is nssBadCert.
-      var gIsCertError;
-
       function getCSSClass()
       {
-        var url = document.documentURI;
-        var matches = url.match(/s\=([^&]+)\&/);
-        // s is optional, if no match just return nothing
-        if (!matches || matches.length < 2)
-          return "";
-
-        // parenthetical match is the second entry
-        return decodeURIComponent(matches[1]);
+        return searchParams.get("s");
       }
 
       function getDescription()
       {
-        var url = document.documentURI;
-        var desc = url.search(/d\=/);
-
-        // desc == -1 if not found; if so, return an empty string
-        // instead of what would turn out to be portions of the URI
-        if (desc == -1)
-          return "";
-
-        return decodeURIComponent(url.slice(desc + 2));
+        return searchParams.get("d");
       }
 
       function retryThis(buttonEl)
       {
         // Note: The application may wish to handle switching off "offline mode"
         // before this event handler runs, but using a capturing event handler.
 
         // Session history has the URL of the page that failed