Bug 1321719 - Location URL should use Get/SetFilePath in nsIURIWithQuery, r=valentin
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 07 Dec 2016 16:29:25 -1000
changeset 325400 cb095e4247e2b059e0af8427e32e4da55cd7edb1
parent 325399 20592ce9283ddf9dea5704cb0db1f44130d2630b
child 325401 f7e0dfe88d42e4c326fdb75b1ebd4228fd1d2f01
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersvalentin
bugs1321719
milestone53.0a1
Bug 1321719 - Location URL should use Get/SetFilePath in nsIURIWithQuery, r=valentin
dom/base/Location.cpp
dom/url/tests/mochitest.ini
dom/url/tests/test_bloburl_location.html
--- a/dom/base/Location.cpp
+++ b/dom/base/Location.cpp
@@ -576,17 +576,17 @@ Location::GetPathname(nsAString& aPathna
 {
   aPathname.Truncate();
 
   nsCOMPtr<nsIURI> uri;
   nsresult result = NS_OK;
 
   result = GetURI(getter_AddRefs(uri));
 
-  nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
+  nsCOMPtr<nsIURIWithQuery> url(do_QueryInterface(uri));
   if (url) {
     nsAutoCString file;
 
     result = url->GetFilePath(file);
 
     if (NS_SUCCEEDED(result)) {
       AppendUTF8toUTF16(file, aPathname);
     }
@@ -599,22 +599,22 @@ NS_IMETHODIMP
 Location::SetPathname(const nsAString& aPathname)
 {
   nsCOMPtr<nsIURI> uri;
   nsresult rv = GetWritableURI(getter_AddRefs(uri));
   if (NS_WARN_IF(NS_FAILED(rv) || !uri)) {
     return rv;
   }
 
-  rv = uri->SetPath(NS_ConvertUTF16toUTF8(aPathname));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
+  nsCOMPtr<nsIURIWithQuery> url(do_QueryInterface(uri));
+  if (url && NS_SUCCEEDED(url->SetFilePath(NS_ConvertUTF16toUTF8(aPathname)))) {
+    return SetURI(uri);
   }
 
-  return SetURI(uri);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 Location::GetPort(nsAString& aPort)
 {
   aPort.SetLength(0);
 
   nsCOMPtr<nsIURI> uri;
--- a/dom/url/tests/mochitest.ini
+++ b/dom/url/tests/mochitest.ini
@@ -13,8 +13,9 @@ support-files =
 [test_urlSearchParams.html]
 [test_urlSearchParams_utf8.html]
 [test_urlutils_stringify.html]
 [test_worker_url.html]
 [test_worker_urlApi.html]
 [test_worker_url_exceptions.html]
 [test_worker_urlSearchParams.html]
 [test_unknown_url_origin.html]
+[test_bloburl_location.html]
new file mode 100644
--- /dev/null
+++ b/dom/url/tests/test_bloburl_location.html
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test for blobURL in location</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+  <script type="application/javascript">
+
+var expectedData = null;
+onmessage = function(e) {
+  if (expectedData === null) {
+    expectedData = e.data;
+  } else {
+    is(e.data, expectedData, "Pathname should be not be changed");
+    SimpleTest.finish();
+  }
+}
+
+var ifr = document.createElement('iframe');
+document.body.appendChild(ifr);
+
+ifr.src = "data:html,<script>location=URL.createObjectURL(new%20Blob(['<script>parent.postMessage(location.pathname,\"*\");location.pathname=\"foo\";parent.postMessage(location.pathname,\"*\");<\/s' +'cript>'], {type:\"text/html\"}));<\/script>";
+
+SimpleTest.waitForExplicitFinish();
+
+  </script>
+</body>
+</html>