Bug 1328894 part 1. Don't navigate when location.protocol is set to anything other than http or https. r=bkelly
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 08 Feb 2017 18:19:01 -0500
changeset 341572 1d229f56d3baae59cd38c3e0d0259f0a2af80d65
parent 341571 bdea29a8b0f3ff50b1a4457f716bb671c4149155
child 341573 7ebd23243cdf2a1e6bffabaacf0818d70e5fedc9
push id31338
push usercbook@mozilla.com
push dateThu, 09 Feb 2017 15:04:28 +0000
treeherdermozilla-central@88d6a5ed1018 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1328894
milestone54.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 1328894 part 1. Don't navigate when location.protocol is set to anything other than http or https. r=bkelly
dom/base/Location.cpp
testing/web-platform/meta/html/browsers/history/the-location-interface/location-protocol-setter-non-broken-weird.html.ini
testing/web-platform/meta/html/browsers/history/the-location-interface/location-protocol-setter-non-broken.html.ini
--- a/dom/base/Location.cpp
+++ b/dom/base/Location.cpp
@@ -709,16 +709,33 @@ Location::SetProtocol(const nsAString& a
     return rv;
   }
   // We may want a new URI class for the new URI, so recreate it:
   rv = NS_NewURI(getter_AddRefs(uri), newSpec);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
+  bool isHttp;
+  rv = uri->SchemeIs("http", &isHttp);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  bool isHttps;
+  rv = uri->SchemeIs("https", &isHttps);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  if (!isHttp && !isHttps) {
+    // No-op, per spec.
+    return NS_OK;
+  }
+
   return SetURI(uri);
 }
 
 NS_IMETHODIMP
 Location::GetSearch(nsAString& aSearch)
 {
   aSearch.SetLength(0);
 
--- a/testing/web-platform/meta/html/browsers/history/the-location-interface/location-protocol-setter-non-broken-weird.html.ini
+++ b/testing/web-platform/meta/html/browsers/history/the-location-interface/location-protocol-setter-non-broken-weird.html.ini
@@ -1,5 +1,5 @@
 [location-protocol-setter-non-broken-weird.html]
   type: testharness
-  [Set location.protocol to x]
+  [Set location.protocol to data]
     expected: FAIL
 
--- a/testing/web-platform/meta/html/browsers/history/the-location-interface/location-protocol-setter-non-broken.html.ini
+++ b/testing/web-platform/meta/html/browsers/history/the-location-interface/location-protocol-setter-non-broken.html.ini
@@ -1,37 +1,5 @@
 [location-protocol-setter-non-broken.html]
   type: testharness
-  disabled: https://github.com/w3c/web-platform-tests/issues/4720
-  expected: OK
-  [Set HTTP URL frame location.protocol to x]
-    expected: FAIL
-
-  [Set data URL frame location.protocol to x]
-    expected: FAIL
-
   [Set HTTP URL frame location.protocol to data]
     expected: FAIL
 
-  [Set data URL frame location.protocol to data]
-    expected: PASS
-
-  [Set HTTP URL frame location.protocol to file]
-    expected: FAIL
-
-  [Set data URL frame location.protocol to file]
-    expected: FAIL
-
-  [Set data URL frame location.protocol to ftp]
-    expected: PASS
-
-  [Set HTTP URL frame location.protocol to gopher]
-    expected: FAIL
-
-  [Set data URL frame location.protocol to gopher]
-    expected: FAIL
-
-  [Set HTTP URL frame location.protocol to http+x]
-    expected: FAIL
-
-  [Set data URL frame location.protocol to http+x]
-    expected: FAIL
-