[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser] 41/73: Bug 1774155 - Avoid copying data URI specs in deprecation warning. r=mccr8, a=RyanVM



This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch geckoview-102.3.0esr-12.0-1
in repository tor-browser.

commit 98d205b30ab79a8a88bf58b7202a3de2a095a484
Author: Adam Vandolder <avandolder@xxxxxxxxxxx>
AuthorDate: Wed Aug 17 02:18:22 2022 +0000

    Bug 1774155 - Avoid copying data URI specs in deprecation warning. r=mccr8, a=RyanVM
    
    Differential Revision: https://phabricator.services.mozilla.com/D154692
---
 dom/bindings/BindingUtils.cpp            | 26 +++++++++++++++++---------
 dom/reporting/tests/common_deprecated.js | 31 ++++++++++++++++++++++++++++++-
 dom/reporting/tests/test_deprecated.html |  1 +
 3 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp
index b1d298d88e0e5..af500c1f3128d 100644
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -4090,14 +4090,22 @@ void ReportDeprecation(nsIGlobalObject* aGlobal, nsIURI* aURI,
                        const Nullable<uint32_t>& aColumnNumber) {
   MOZ_ASSERT(aURI);
 
-  // Anonymize the URL.
-  // Strip the URL of any possible username/password and make it ready to be
-  // presented in the UI.
-  nsCOMPtr<nsIURI> exposableURI = net::nsIOService::CreateExposableURI(aURI);
-  nsAutoCString spec;
-  nsresult rv = exposableURI->GetSpec(spec);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return;
+  // If the URI has the data scheme, report that instead of the spec,
+  // as the spec may be arbitrarily long and we would like to avoid
+  // copying it.
+  nsAutoCString specOrScheme;
+  nsresult rv;
+  if (aURI->SchemeIs("data")) {
+    specOrScheme.Assign("data:..."_ns);
+  } else {
+    // Anonymize the URL.
+    // Strip the URL of any possible username/password and make it ready to be
+    // presented in the UI.
+    nsCOMPtr<nsIURI> exposableURI = net::nsIOService::CreateExposableURI(aURI);
+    rv = exposableURI->GetSpec(specOrScheme);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return;
+    }
   }
 
   nsAutoString type;
@@ -4142,7 +4150,7 @@ void ReportDeprecation(nsIGlobalObject* aGlobal, nsIURI* aURI,
                                 aFileName, aLineNumber, aColumnNumber);
 
   ReportingUtils::Report(aGlobal, nsGkAtoms::deprecation, u"default"_ns,
-                         NS_ConvertUTF8toUTF16(spec), body);
+                         NS_ConvertUTF8toUTF16(specOrScheme), body);
 }
 
 // This runnable is used to write a deprecation message from a worker to the
diff --git a/dom/reporting/tests/common_deprecated.js b/dom/reporting/tests/common_deprecated.js
index 535945d6d586c..1cee9481c2e92 100644
--- a/dom/reporting/tests/common_deprecated.js
+++ b/dom/reporting/tests/common_deprecated.js
@@ -102,6 +102,35 @@ function test_deprecatedMethod() {
   });
 }
 
+// eslint-disable-next-line no-unused-vars
+function test_deprecatedMethodWithDataURI() {
+  info("Testing deprecatedMethodWithDataURI report");
+
+  const uri = `data:text/html,<script>
+    window.onload = () => {
+      let obs = new ReportingObserver((reports, o) => {
+        obs.disconnect();
+        let report = reports[0];
+        const message = (report.url == "data:...") ? "passed" : "failed";
+        window.opener.postMessage(message, "http://mochi.test:8888";);
+        close();
+      });
+
+      obs.observe();
+      let testingInterface = new TestingDeprecatedInterface();
+      testingInterface.deprecatedMethod();
+    };
+  </script>`;
+
+  return new Promise((resolve, reject) => {
+    window.open(uri);
+    window.addEventListener("message", e => {
+      is(e.data, "passed", "The data URI is truncated");
+      resolve();
+    });
+  });
+}
+
 // eslint-disable-next-line no-unused-vars
 function test_deprecatedAttribute() {
   info("Testing DeprecatedTestingAttribute report");
@@ -138,7 +167,7 @@ function test_deprecatedAttribute() {
           .replace("worker_deprecated.js", "common_deprecated.js"),
         "We have a sourceFile"
       );
-      is(report.body.lineNumber, 152, "We have a lineNumber");
+      is(report.body.lineNumber, 181, "We have a lineNumber");
       is(report.body.columnNumber, 4, "We have a columnNumber");
 
       obs.disconnect();
diff --git a/dom/reporting/tests/test_deprecated.html b/dom/reporting/tests/test_deprecated.html
index d0fa7f2d39b88..da55978e9b33f 100644
--- a/dom/reporting/tests/test_deprecated.html
+++ b/dom/reporting/tests/test_deprecated.html
@@ -12,6 +12,7 @@
 
 test_deprecatedInterface()
 .then(() => test_deprecatedMethod())
+.then(() => test_deprecatedMethodWithDataURI())
 .then(() => test_deprecatedAttribute())
 .then(() => test_takeRecords())
 .then(() => {

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits