Bug 1422643 - deal with tabs in the protocol in js paste detection code, r=florian,valentin
☠☠ backed out by ea1837bc4e1f ☠ ☠
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 20 Dec 2017 18:57:48 +0000
changeset 397898 6ad5ec88a8982d83b8097fd76a2383aae94711c6
parent 397897 6a44449562d57024cff1d6bf09b1e0c191b45694
child 397899 ea1837bc4e1fb9eae72fae99cfb205c5b662d432
push id57559
push usergijskruitbosch@gmail.com
push dateThu, 04 Jan 2018 23:32:01 +0000
treeherderautoland@6ad5ec88a898 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian, valentin
bugs1422643
milestone59.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 1422643 - deal with tabs in the protocol in js paste detection code, r=florian,valentin MozReview-Commit-ID: Ax5LGkIedkY
browser/base/content/browser.js
browser/base/content/test/urlbar/browser_removeUnsafeProtocolsFromURLBarPaste.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -6047,24 +6047,28 @@ function middleMousePaste(event) {
   });
 
   event.stopPropagation();
 }
 
 function stripUnsafeProtocolOnPaste(pasteData) {
   // Don't allow pasting javascript URIs since we don't support
   // LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL for those.
-  let changed = false;
-  let pasteDataNoJS = pasteData.replace(/\r?\n/g, "")
-                               .replace(/^(?:\W*javascript:)+/i,
-                                        () => {
-                                                changed = true;
-                                                return "";
-                                              });
-  return changed ? pasteDataNoJS : pasteData;
+  while (true) {
+    let scheme = "";
+    try {
+      scheme = Services.io.extractScheme(pasteData);
+    } catch (ex) { }
+    if (scheme != "javascript") {
+      break;
+    }
+
+    pasteData = pasteData.substring(pasteData.indexOf(":") + 1);
+  }
+  return pasteData;
 }
 
 // handleDroppedLink has the following 2 overloads:
 //   handleDroppedLink(event, url, name, triggeringPrincipal)
 //   handleDroppedLink(event, links, triggeringPrincipal)
 function handleDroppedLink(event, urlOrLinks, nameOrTriggeringPrincipal, triggeringPrincipal) {
   let links;
   if (Array.isArray(urlOrLinks)) {
--- a/browser/base/content/test/urlbar/browser_removeUnsafeProtocolsFromURLBarPaste.js
+++ b/browser/base/content/test/urlbar/browser_removeUnsafeProtocolsFromURLBarPaste.js
@@ -3,17 +3,20 @@ function test() {
   testNext();
 }
 
 var pairs = [
   ["javascript:", ""],
   ["javascript:1+1", "1+1"],
   ["javascript:document.domain", "document.domain"],
   [" \u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009javascript:document.domain", "document.domain"],
+  ["\u0000\u000a\u000b\u000c\u000d\u000e\u000f\u0010\u0011\u0012\u0013\u0014javascript:document.domain", "document.domain"],
   ["java\nscript:foo", "foo"],
+  ["java\rscript:foo", "foo"],
+  ["java\tscript:foo", "foo"],
   ["http://\nexample.com", "http://example.com"],
   ["http://\nexample.com\n", "http://example.com"],
   ["data:text/html,<body>hi</body>", "data:text/html,<body>hi</body>"],
   // Nested things get confusing because some things don't parse as URIs:
   ["javascript:javascript:alert('hi!')", "alert('hi!')"],
   ["data:data:text/html,<body>hi</body>", "data:data:text/html,<body>hi</body>"],
   ["javascript:data:javascript:alert('hi!')", "data:javascript:alert('hi!')"],
   ["javascript:data:text/html,javascript:alert('hi!')", "data:text/html,javascript:alert('hi!')"],