Bug 1160892 - Url.createObjectURL(blob) should support punycode origins, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 07 May 2015 19:20:33 +0100
changeset 274229 ddab177fd4c4877ce7ff372666558aab25138947
parent 274228 a74ede09893fc7cb4a6fa1dbbac0c758595aa3bb
child 274230 a28f0621cf7edb2b1790eea3ba89f0bac51fbfaa
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1160892
milestone40.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 1160892 - Url.createObjectURL(blob) should support punycode origins, r=smaug
dom/base/nsHostObjectProtocolHandler.cpp
dom/base/test/file_nonascii_blob_url.html
dom/base/test/mochitest.ini
dom/base/test/test_nonascii_blob_url.html
--- a/dom/base/nsHostObjectProtocolHandler.cpp
+++ b/dom/base/nsHostObjectProtocolHandler.cpp
@@ -386,23 +386,23 @@ nsHostObjectProtocolHandler::GenerateURI
 
   char chars[NSID_LENGTH];
   id.ToProvidedString(chars);
 
   aUri = aScheme;
   aUri.Append(':');
 
   if (aPrincipal) {
-    nsAutoString origin;
-    rv = nsContentUtils::GetUTFOrigin(aPrincipal, origin);
+    nsAutoCString origin;
+    rv = nsContentUtils::GetASCIIOrigin(aPrincipal, origin);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
-    AppendUTF16toUTF8(origin, aUri);
+    aUri.Append(origin);
     aUri.Append('/');
   }
 
   aUri += Substring(chars + 1, chars + NSID_LENGTH - 2);
 
   return NS_OK;
 }
 
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_nonascii_blob_url.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>Test blob URL for non-ascii domain</title>
+</head>
+<body>
+  <p id="result"></p>
+  <script type="application/javascript">
+
+window.onmessage = function(e) {
+  var blob = new Blob([e.data]);
+  var url = URL.createObjectURL(blob);
+
+  var xhr = new XMLHttpRequest();
+  xhr.open('GET', url, false);
+  xhr.send(null);
+
+  parent.postMessage(xhr.responseText, '*');
+}
+
+  </script>
+</body>
+</html>
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -236,16 +236,17 @@ support-files =
   script_bug602838.sjs
   send_gzip_content.sjs
   somedatas.resource
   somedatas.resource^headers^
   variable_style_sheet.sjs
   viewport_helpers.js
   w3element_traversal.svg
   wholeTexty-helper.xml
+  file_nonascii_blob_url.html
 
 [test_anonymousContent_api.html]
 [test_anonymousContent_append_after_reflow.html]
 [test_anonymousContent_insert.html]
 [test_anonymousContent_manipulate_content.html]
 [test_appname_override.html]
 [test_audioWindowUtils.html]
 [test_audioNotification.html]
@@ -777,8 +778,9 @@ skip-if = true # bug 1107443 - code for 
 [test_performance_user_timing.html]
 [test_bug1126851.html]
 skip-if = buildapp == 'mulet' || buildapp == 'b2g'
 [test_bug1118689.html]
 skip-if = buildapp == 'mulet' || buildapp == 'b2g'
 [test_integer_attr_with_leading_zero.html]
 [test_script_loader_crossorigin_data_url.html]
 [test_file_negative_date.html]
+[test_nonascii_blob_url.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_nonascii_blob_url.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test blob URL for non-ascii domain</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="fileutils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<div id="content"></div>
+<script class="testbody" type="text/javascript;version=1.7">
+
+var iframe = document.createElement('iframe');
+iframe.src = 'http://xn--exmple-cua.test/tests/dom/base/test/file_nonascii_blob_url.html';
+iframe.onload = function() {
+  iframe.contentWindow.postMessage('hello world', '*');
+  onmessage = function(e) {
+    is(e.data, 'hello world', "Blob URL for non-ascii domain works");
+    SimpleTest.finish();
+  }
+}
+
+document.getElementById('content').appendChild(iframe);
+SimpleTest.waitForExplicitFinish();
+
+</script>
+</pre>
+</body>
+</html>