Bug 1402715 - Treat URL bar contents as raw text when copying. r=mak, a=sledru
authorMats Palmgren <mats@mozilla.com>
Wed, 27 Sep 2017 14:12:01 +0200
changeset 431975 d843bac9f3f428b4fc2cbd93677e091aa2de85c3
parent 431974 d0134315fc7d21942776e60a5610cea9d7ee4b62
child 431976 81bcbd6fa446f6f38fb567a942ac496f919fe7c2
push id7847
push userryanvm@gmail.com
push dateThu, 28 Sep 2017 18:02:07 +0000
treeherdermozilla-beta@1c3b6791f943 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, sledru
bugs1402715
milestone57.0
Bug 1402715 - Treat URL bar contents as raw text when copying. r=mak, a=sledru MozReview-Commit-ID: LuSvwRUVwAq
browser/base/content/test/urlbar/browser_urlbarCopying.js
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/test/urlbar/browser_urlbarCopying.js
+++ b/browser/base/content/test/urlbar/browser_urlbarCopying.js
@@ -159,16 +159,21 @@ var tests = [
   {
     copyVal: "e<xample.com/?\xf7>\xf7",
     copyExpected: "xample.com/?\xf7"
   },
   {
     copyVal: "<example.com/?\xf7>\xf7",
     copyExpected: "http://example.com/?\xf7"
   },
+  {
+    loadURL: "http://example.com/%20%20%20",
+    expectedURL: "example.com/   ",
+    copyExpected: "http://example.com/%20%20%20"
+  },
 
   // data: and javsacript: URIs shouldn't be encoded
   {
     loadURL: "javascript:('%C3%A9%20%25%50')",
     expectedURL: "javascript:('%C3%A9 %25P')",
     copyExpected: "javascript:('%C3%A9 %25P')"
   },
   {
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -967,17 +967,20 @@ file, You can obtain one at http://mozil
         </body>
       </method>
 
       <method name="_getSelectedValueForClipboard">
         <body><![CDATA[
           // Grab the actual input field's value, not our value, which could include moz-action:
           var inputVal = this.inputField.value;
           let selection = this.editor.selection;
-          var selectedVal = selection.toString();
+          const flags = Ci.nsIDocumentEncoder.OutputPreformatted |
+                        Ci.nsIDocumentEncoder.OutputRaw;
+          let selectedVal = selection.QueryInterface(Ci.nsISelectionPrivate)
+                                     .toStringWithFormat("text/plain", flags, 0);
 
           // Handle multiple-range selection as a string for simplicity.
           if (selection.rangeCount > 1) {
              return selectedVal;
           }
 
           // If the selection doesn't start at the beginning or doesn't span the full domain or
           // the URL bar is modified or there is no text at all, nothing else to do here.