Bug 792968 - Replace some regular expression string matches with String.startsWith and replace /^https?/ URI scheme tests with /^https?$/. r=dao
☠☠ backed out by a21e1c1d2ba8 ☠ ☠
authorYosy <yosy101@gmail.com>
Sun, 23 Sep 2012 16:48:23 +0200
changeset 107959 3ca1f19e4c2a80361f8ec868997cb78c3ba1e5a1
parent 107958 7eabbf24ef96c224539879ec927e49d1e5aa5151
child 107960 a21e1c1d2ba82b36293bbc7e70ab7bd2ea2f7b5d
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersdao
bugs792968
milestone18.0a1
Bug 792968 - Replace some regular expression string matches with String.startsWith and replace /^https?/ URI scheme tests with /^https?$/. r=dao
browser/base/content/browser-feeds.js
browser/base/content/browser-safebrowsing.js
browser/base/content/browser-tabPreviews.js
browser/base/content/browser.js
browser/base/content/pageinfo/pageInfo.js
browser/base/content/pageinfo/permissions.js
browser/base/content/urlbarBindings.xml
browser/components/certerror/test/browser_bug431826.js
browser/components/downloads/src/DownloadsCommon.jsm
browser/components/feeds/src/FeedWriter.js
browser/components/places/content/controller.js
browser/components/preferences/applications.js
browser/components/preferences/in-content/applications.js
browser/components/safebrowsing/content/blockedSite.xhtml
browser/components/tabview/test/browser_tabview_bug600645.js
--- a/browser/base/content/browser-feeds.js
+++ b/browser/base/content/browser-feeds.js
@@ -90,17 +90,17 @@ var FeedHandler = {
     // preview UI
     if (!href)
       href = event.target.getAttribute("feed");
     urlSecurityCheck(href, gBrowser.contentPrincipal,
                      Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
     var feedURI = makeURI(href, document.characterSet);
     // Use the feed scheme so X-Moz-Is-Feed will be set
     // The value doesn't matter
-    if (/^https?/.test(feedURI.scheme))
+    if (/^https?$/.test(feedURI.scheme))
       href = "feed:" + href;
     this.loadFeed(href, event);
   },
 
   loadFeed: function(href, event) {
     var feeds = gBrowser.selectedBrowser.feeds;
     try {
       openUILink(href, event, { ignoreAlt: true });
--- a/browser/base/content/browser-safebrowsing.js
+++ b/browser/base/content/browser-safebrowsing.js
@@ -3,17 +3,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #ifdef MOZ_SAFE_BROWSING
 var gSafeBrowsing = {
 
   setReportPhishingMenu: function() {
 
     // A phishing page will have a specific about:blocked content documentURI
-    var isPhishingPage = /^about:blocked\?e=phishingBlocked/.test(content.document.documentURI);
+    var isPhishingPage = content.document.documentURI.startsWith("about:blocked?e=phishingBlocked");
 
     // Show/hide the appropriate menu item.
     document.getElementById("menu_HelpPopup_reportPhishingtoolmenu")
             .hidden = isPhishingPage;
     document.getElementById("menu_HelpPopup_reportPhishingErrortoolmenu")
             .hidden = !isPhishingPage;
 
     var broadcasterId = isPhishingPage
--- a/browser/base/content/browser-tabPreviews.js
+++ b/browser/base/content/browser-tabPreviews.js
@@ -730,17 +730,17 @@ var allTabs = {
     this._browserCommandSet.removeEventListener("command", this, false);
 
     setTimeout(function () {
       document.getElementById("Browser:ShowAllTabs").removeAttribute("disabled");
     }, 300);
   },
 
   handleEvent: function allTabs_handleEvent(event) {
-    if (/^Tab/.test(event.type)) {
+    if (event.type.startsWith("Tab")) {
       var tab = event.target;
       if (event.type != "TabOpen")
         var preview = this._getPreview(tab);
     }
     switch (event.type) {
       case "TabAttrModified":
         // tab attribute modified (e.g. label, crop, busy, image)
         if (!preview.hidden)
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2516,23 +2516,23 @@ let BrowserOnClick = {
       return;
     }
 
     let originalTarget = aEvent.originalTarget;
     let ownerDoc = originalTarget.ownerDocument;
 
     // If the event came from an ssl error page, it is probably either the "Add
     // Exception…" or "Get me out of here!" button
-    if (/^about:certerror/.test(ownerDoc.documentURI)) {
+    if (ownerDoc.documentURI.startsWith("about:certerror")) {
       this.onAboutCertError(originalTarget, ownerDoc);
     }
-    else if (/^about:blocked/.test(ownerDoc.documentURI)) {
+    else if (ownerDoc.documentURI.startsWith("about:blocked")) {
       this.onAboutBlocked(originalTarget, ownerDoc);
     }
-    else if (/^about:neterror/.test(ownerDoc.documentURI)) {
+    else if (ownerDoc.documentURI.startsWith("about:neterror")) {
       this.onAboutNetError(originalTarget, ownerDoc);
     }
     else if (/^about:home$/i.test(ownerDoc.documentURI)) {
       this.onAboutHome(originalTarget, ownerDoc);
     }
   },
 
   onAboutCertError: function BrowserOnClick_onAboutCertError(aTargetElm, aOwnerDoc) {
@@ -4476,17 +4476,17 @@ var TabsProgressListener = {
     // pages and other similar page. This lets us fix bugs like 401575 which
     // require error page UI to do privileged things, without letting error
     // pages have any privilege themselves.
     // We can't look for this during onLocationChange since at that point the
     // document URI is not yet the about:-uri of the error page.
 
     if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
         Components.isSuccessCode(aStatus) &&
-        /^about:/.test(aWebProgress.DOMWindow.document.documentURI)) {
+        aWebProgress.DOMWindow.document.documentURI.startsWith("about:")) {
       aBrowser.addEventListener("click", BrowserOnClick, true);
       aBrowser.addEventListener("pagehide", function onPageHide(event) {
         if (event.target.defaultView.frameElement)
           return;
         aBrowser.removeEventListener("click", BrowserOnClick, true);
         aBrowser.removeEventListener("pagehide", onPageHide, true);
       }, true);
 
--- a/browser/base/content/pageinfo/pageInfo.js
+++ b/browser/base/content/pageinfo/pageInfo.js
@@ -156,17 +156,17 @@ var atomSvc = Components.classes["@mozil
 gImageView._ltrAtom = atomSvc.getAtom("ltr");
 gImageView._brokenAtom = atomSvc.getAtom("broken");
 
 gImageView.getCellProperties = function(row, col, props) {
   var data = gImageView.data[row];
   var item = gImageView.data[row][COL_IMAGE_NODE];
   if (!checkProtocol(data) ||
       item instanceof HTMLEmbedElement ||
-      (item instanceof HTMLObjectElement && !/^image\//.test(item.type)))
+      (item instanceof HTMLObjectElement && !item.type.startsWith("image/"))
     props.AppendElement(this._brokenAtom);
 
   if (col.element.id == "image-address")
     props.AppendElement(this._ltrAtom);
 };
 
 gImageView.getCellText = function(row, column) {
   var value = this.data[row][column.index];
@@ -940,17 +940,17 @@ function makePreview(row)
           numFrames = image.numFrames;
       }
     }
     
     if (!mimeType)
       mimeType = getContentTypeFromHeaders(cacheEntry);
 
     // if we have a data url, get the MIME type from the url
-    if (!mimeType && /^data:/.test(url)) {
+    if (!mimeType && url.startsWith("data:")) {
       let dataMimeType = /^data:(image\/[^;,]+)/i.exec(url);
       if (dataMimeType)
         mimeType = dataMimeType[1].toLowerCase();
     }
 
     var imageType;
     if (mimeType) {
       // We found the type, try to display it nicely
@@ -982,17 +982,17 @@ function makePreview(row)
     var newImage = new Image;
     newImage.id = "thepreviewimage";
     var physWidth = 0, physHeight = 0;
     var width = 0, height = 0;
 
     if ((item instanceof HTMLLinkElement || item instanceof HTMLInputElement ||
          item instanceof HTMLImageElement ||
          item instanceof SVGImageElement ||
-        (item instanceof HTMLObjectElement && /^image\//.test(mimeType)) || isBG) && isProtocolAllowed) {
+         (item instanceof HTMLObjectElement && mimeType.startsWith("image/")) || isBG) && isProtocolAllowed) {
       newImage.setAttribute("src", url);
       physWidth = newImage.width || 0;
       physHeight = newImage.height || 0;
 
       // "width" and "height" attributes must be set to newImage,
       // even if there is no "width" or "height attribute in item;
       // otherwise, the preview image cannot be displayed correctly.
       if (!isBG) {
--- a/browser/base/content/pageinfo/permissions.js
+++ b/browser/base/content/pageinfo/permissions.js
@@ -78,17 +78,17 @@ var permissionObserver = {
 
 function onLoadPermission()
 {
   gPrefs = Components.classes[PREFERENCES_CONTRACTID]
                      .getService(Components.interfaces.nsIPrefBranch);
 
   var uri = gDocument.documentURIObject;
   var permTab = document.getElementById("permTab");
-  if(/^https?/.test(uri.scheme)) {
+  if (/^https?$/.test(uri.scheme)) {
     gPermURI = uri;
     var hostText = document.getElementById("hostText");
     hostText.value = gPermURI.host;
 
     for (var i in gPermObj)
       initRow(i);
     var os = Components.classes["@mozilla.org/observer-service;1"]
                        .getService(Components.interfaces.nsIObserverService);
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -640,17 +640,17 @@
           return this.value;
           ]]>
         </setter>
       </property>
 
       <method name="_parseActionUrl">
         <parameter name="aUrl"/>
         <body><![CDATA[
-          if (!/^moz-action:/.test(aUrl))
+          if (!aUrl.startsWith("moz-action:"))
             return null;
 
           // url is in the format moz-action:ACTION,PARAM
           let [, action, param] = aUrl.match(/^moz-action:([^,]+),(.*)$/);
           return {type: action, param: param};
         ]]></body>
       </method>
 
@@ -1610,17 +1610,17 @@
         ]]></setter>
       </property>
       <property name="_notificationType">
         <getter><![CDATA[
           // Use the popupid attribute to identify the notification type,
           // otherwise just rely on the panel id for common arrowpanels.
           let type = this._panel.firstChild.getAttribute("popupid") ||
                      this._panel.id;
-          if (/^password-/.test(type))
+          if (type.startsWith("password-"))
             return "passwords";
           if (type == "editBookmarkPanel")
             return "bookmarks";
           if (type == "addon-install-complete") {
             if (!Services.prefs.prefHasUserValue("services.sync.username"))
               return "addons";
             if (!Services.prefs.getBoolPref("services.sync.engine.addons"))
               return "addons-sync-disabled";
--- a/browser/components/certerror/test/browser_bug431826.js
+++ b/browser/components/certerror/test/browser_bug431826.js
@@ -7,17 +7,17 @@ function test() {
   window.addEventListener("DOMContentLoaded", testBrokenCert, true);
   content.location = "https://nocert.example.com/";
 }
 
 function testBrokenCert() {
   window.removeEventListener("DOMContentLoaded", testBrokenCert, true);
 
   // Confirm that we are displaying the contributed error page, not the default
-  ok(/^about:certerror/.test(gBrowser.contentDocument.documentURI), "Broken page should go to about:certerror, not about:neterror");
+  ok(gBrowser.contentDocument.documentURI.startsWith("about:certerror"), "Broken page should go to about:certerror, not about:neterror");
 
   // Confirm that the expert section is collapsed
   var expertDiv = gBrowser.contentDocument.getElementById("expertContent");
   ok(expertDiv, "Expert content div should exist");
   ok(expertDiv.hasAttribute("collapsed"), "Expert content should be collapsed by default");
 
   // Tweak the expert mode pref
   gPrefService.setBoolPref("browser.xul.error_pages.expert_bad_cert", true);
--- a/browser/components/downloads/src/DownloadsCommon.jsm
+++ b/browser/components/downloads/src/DownloadsCommon.jsm
@@ -859,17 +859,17 @@ DownloadsDataItem.prototype = {
    *         profile is used on different platforms, for example if a native
    *         Windows path is stored and then the item is accessed on a Mac.
    */
   get localFile()
   {
     // The download database may contain targets stored as file URLs or native
     // paths.  This can still be true for previously stored items, even if new
     // items are stored using their file URL.  See also bug 239948 comment 12.
-    if (/^file:/.test(this.file)) {
+    if (this.file.startsWith("file:")) {
       // Assume the file URL we obtained from the downloads database or from the
       // "spec" property of the target has the UTF-8 charset.
       let fileUrl = NetUtil.newURI(this.file).QueryInterface(Ci.nsIFileURL);
       return fileUrl.file.clone().QueryInterface(Ci.nsILocalFile);
     } else {
       // The downloads database contains a native path.  Try to create a local
       // file, though this may throw an exception if the path is invalid.
       return new DownloadsLocalFileCtor(this.file);
--- a/browser/components/feeds/src/FeedWriter.js
+++ b/browser/components/feeds/src/FeedWriter.js
@@ -1335,17 +1335,17 @@ FeedWriter.prototype = {
    *        the reader item in the readers menulist.
    *
    * @note For privacy reasons we cannot set the image attribute directly
    *       to the icon url.  See Bug 358878 for details.
    */
   _setFaviconForWebReader:
   function FW__setFaviconForWebReader(aReaderUrl, aMenuItem) {
     var readerURI = makeURI(aReaderUrl);
-    if (!/^https?/.test(readerURI.scheme)) {
+    if (!/^https?$/.test(readerURI.scheme)) {
       // Don't try to get a favicon for non http(s) URIs.
       return;
     }
     var faviconURI = makeURI(readerURI.prePath + "/favicon.ico");
     var self = this;
     var usePrivateBrowsing = this._window.QueryInterface(Ci.nsIInterfaceRequestor)
                                          .getInterface(Ci.nsIWebNavigation)
                                          .QueryInterface(Ci.nsIDocShell)
--- a/browser/components/places/content/controller.js
+++ b/browser/components/places/content/controller.js
@@ -1420,23 +1420,23 @@ let PlacesControllerDragHelper = {
       catch (e) {
         return false;
       }
 
       // Only bookmarks and urls can be dropped into tag containers.
       if (ip.isTag && ip.orientation == Ci.nsITreeView.DROP_ON &&
           dragged.type != PlacesUtils.TYPE_X_MOZ_URL &&
           (dragged.type != PlacesUtils.TYPE_X_MOZ_PLACE ||
-           /^place:/.test(dragged.uri)))
+           dragged.uri.startsWith("place:")))
         return false;
 
       // The following loop disallows the dropping of a folder on itself or
       // on any of its descendants.
       if (dragged.type == PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER ||
-          /^place:/.test(dragged.uri)) {
+          dragged.uri.startsWith("place:")) {
         let parentId = ip.itemId;
         while (parentId != PlacesUtils.placesRootId) {
           if (dragged.concreteId == parentId || dragged.id == parentId)
             return false;
           parentId = PlacesUtils.bookmarks.getFolderIdForItem(parentId);
         }
       }
     }
--- a/browser/components/preferences/applications.js
+++ b/browser/components/preferences/applications.js
@@ -1882,17 +1882,17 @@ var gApplicationsPane = {
 
     // Unfortunately we can't use the favicon service to get the favicon,
     // because the service looks for a record with the exact URL we give it, and
     // users won't have such records for URLs they don't visit, and users won't
     // visit the handler's URL template, they'll only visit URLs derived from
     // that template (i.e. with %s in the template replaced by the URL of the
     // content being handled).
 
-    if (/^https?/.test(uri.scheme) && this._prefSvc.getBoolPref("browser.chrome.favicons"))
+    if (/^https?$/.test(uri.scheme) && this._prefSvc.getBoolPref("browser.chrome.favicons"))
       return uri.prePath + "/favicon.ico";
 
     return "";
   },
 
   _getIconURLForSystemDefault: function(aHandlerInfo) {
     // Handler info objects for MIME types on some OSes implement a property bag
     // interface from which we can get an icon for the default app, so if we're
--- a/browser/components/preferences/in-content/applications.js
+++ b/browser/components/preferences/in-content/applications.js
@@ -1869,17 +1869,17 @@ var gApplicationsPane = {
 
     // Unfortunately we can't use the favicon service to get the favicon,
     // because the service looks in the annotations table for a record with
     // the exact URL we give it, and users won't have such records for URLs
     // they don't visit, and users won't visit the web app's URL template,
     // they'll only visit URLs derived from that template (i.e. with %s
     // in the template replaced by the URL of the content being handled).
 
-    if (/^https?/.test(uri.scheme) && this._prefSvc.getBoolPref("browser.chrome.favicons"))
+    if (/^https?$/.test(uri.scheme) && this._prefSvc.getBoolPref("browser.chrome.favicons"))
       return uri.prePath + "/favicon.ico";
 
     return "";
   },
 
   _getIconURLForSystemDefault: function(aHandlerInfo) {
     // Handler info objects for MIME types on some OSes implement a property bag
     // interface from which we can get an icon for the default app, so if we're
--- a/browser/components/safebrowsing/content/blockedSite.xhtml
+++ b/browser/components/safebrowsing/content/blockedSite.xhtml
@@ -46,17 +46,17 @@
         // match == null if not found; if so, return an empty string
         // instead of what would turn out to be portions of the URI
         if (!match)
           return "";
 
         url = decodeURIComponent(match[1]);
 
         // If this is a view-source page, then get then real URI of the page
-        if (/^view-source\:/.test(url))
+        if (url.startsWith("view-source:"))
           url = url.slice(12);
         return url;
       }
       
       /**
        * Attempt to get the hostname via document.location.  Fail back
        * to getURL so that we always return something meaningful.
        */
--- a/browser/components/tabview/test/browser_tabview_bug600645.js
+++ b/browser/components/tabview/test/browser_tabview_bug600645.js
@@ -45,17 +45,17 @@ function onTabPinned() {
     // since the browser code and test code are invoked when an error event is 
     // fired, a delay is used here to avoid the test code run before the browser 
     // code.
     executeSoon(function() {
       let iconSrc = $icon.attr("src");
 
       // with moz-anno:favicon automatically redirects to the default favIcon 
       // if the given url is invalid
-      ok(/^moz-anno:favicon:/.test(iconSrc),
+      ok(iconSrc.startsWith("moz-anno:favicon:"),
          "The icon url starts with moz-anno:favicon so the default fav icon would be displayed");
 
       // At this point, as an additional integrity check we could also verify
       // that the iconSrc URI does not have any associated favicon data.  This
       // kind of check, however, is not easily supported by the asynchronous
       // favicon API.  Fortunately, the fact that we received the error event
       // already indicates that the original favicon was not available.
       // Morevover, since we are using a "moz-anno:favicon:" URI, we know that