Bug 1581177 - Port |Bug 989197 - Use URLSearchParams instead of regex to parse params in about:net/certerror URLs| to SeaMonkey. r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sun, 13 Oct 2019 13:21:01 +0200
changeset 37145 de271481efc1a382c67e8bcbb18153167fd93950
parent 37144 e8fe8731e1ae78060be9f2a51563c00f1c57cc05
child 37146 4f7c6fb76db0ea2a8e5194a2f211cd68edb9bc0e
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersfrg
bugs1581177, 989197
Bug 1581177 - Port |Bug 989197 - Use URLSearchParams instead of regex to parse params in about:net/certerror URLs| to SeaMonkey. r=frg
suite/base/content/certError.js
--- a/suite/base/content/certError.js
+++ b/suite/base/content/certError.js
@@ -1,59 +1,51 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-// Error url MUST be formatted like this:
-//   about:certerror?e=error&u=url&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.
 
 // setting up the event listeners and initializing the page
 // in this way given that window.onload won't work here
 
 document.getElementById("technicalContentHeading")
         .addEventListener("click", function() { toggle("technicalContent"); });
 
 document.getElementById("expertContentHeading")
         .addEventListener("click", function() { toggle("expertContent"); });
 
+let gSearchParams;
+
 initPage();
 
-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]);
+function getErrorCode() {
+  return gSearchParams.get("e");
 }
 
-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));
+function getCSSClass() {
+  return gSearchParams.get("s");
 }
 
-function initPage()
-{
+function getDescription() {
+  return gSearchParams.get("d");
+}
+
+function initPage() {
+  gSearchParams = new URLSearchParams(document.documentURI.split("?")[1]);
+
   var intro = document.getElementById("introContentP1");
   var node = document.evaluate('//text()[string()="#1"]', intro, null,
                                XPathResult.ANY_UNORDERED_NODE_TYPE,
                                null).singleNodeValue;
   if (node)
     node.textContent = location.host;
 
   switch (getCSSClass()) {