Bug 1319533 - Autocompleted URLs are trimmed. r?mak draft
authorHarry Twyford <htwyford@mozilla.com>
Wed, 16 May 2018 14:12:16 -0400
changeset 798408 323bf28b8b9d3532aecf824739e70fbcc486e019
parent 795657 3c9d69736f4a421218e5eb01b6571d535d38318a
push id110749
push userbmo:htwyford@mozilla.com
push dateTue, 22 May 2018 20:10:10 +0000
reviewersmak
bugs1319533
milestone62.0a1
Bug 1319533 - Autocompleted URLs are trimmed. r?mak MozReview-Commit-ID: 6y26a9Nhm3b
browser/base/content/urlbarBindings.xml
toolkit/components/places/UnifiedComplete.js
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -786,16 +786,17 @@ file, You can obtain one at http://mozil
                 this.ExtensionSearchHandler.handleInputEntered(keyword, searchString, where);
                 return;
             }
           } else {
             // This is a fallback for add-ons and old testing code that directly
             // set value and try to confirm it. UnifiedComplete should always
             // resolve to a valid url.
             try {
+              url = url.trim();
               new URL(url);
             } catch (ex) {
               let lastLocationChange = browser.lastLocationChange;
               getShortcutOrURIAndPostData(url).then(data => {
                 if (where != "current" ||
                     browser.lastLocationChange == lastLocationChange) {
                   this._loadURL(data.url, browser, data.postData, where,
                                 openUILinkParams, data.mayInheritPrincipal,
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -1682,32 +1682,33 @@ Search.prototype = {
         icon,
       };
       this._addMatch(match);
     }
   },
 
   // TODO (bug 1054814): Use visited URLs to inform which scheme to use, if the
   // scheme isn't specificed.
+  // Bug 1460097: trimmed search string is used
   _matchUnknownUrl() {
     let flags = Ci.nsIURIFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS |
                 Ci.nsIURIFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
     let fixupInfo = null;
     try {
-      fixupInfo = Services.uriFixup.getFixupURIInfo(this._originalSearchString,
+      fixupInfo = Services.uriFixup.getFixupURIInfo(this._trimmedOriginalSearchString,
                                                     flags);
     } catch (e) {
       if (e.result == Cr.NS_ERROR_MALFORMED_URI && !Prefs.get("keyword.enabled")) {
         let value = PlacesUtils.mozActionURI("visiturl", {
-          url: this._originalSearchString,
-          input: this._originalSearchString,
+          url: this._trimmedOriginalSearchString,
+          input: this._trimmedOriginalSearchString,
         });
         this._addMatch({
           value,
-          comment: this._originalSearchString,
+          comment: this._trimmedOriginalSearchString,
           style: "action visiturl",
           frecency: Infinity
         });
 
         return true;
       }
       return false;
     }
@@ -1734,17 +1735,17 @@ Search.prototype = {
     // pass the pretty, unescaped URL as the match comment, since it's likely
     // to be displayed to the user, and in any case the front-end should not
     // rely on it being canonical.
     let escapedURL = uri.displaySpec;
     let displayURL = Services.textToSubURI.unEscapeURIForUI("UTF-8", escapedURL);
 
     let value = PlacesUtils.mozActionURI("visiturl", {
       url: escapedURL,
-      input: this._originalSearchString,
+      input: this._trimmedOriginalSearchString,
     });
 
     let match = {
       value,
       comment: displayURL,
       style: "action visiturl",
       frecency: Infinity
     };