Bug 1464328 - Autofill urls to-the-next-slash is broken. r=adw draft
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 29 May 2018 17:57:35 +0200
changeset 801030 4d0d7f6cfe6785ac6c32f83ac75264853aa923b9
parent 800961 6b369e88c8da4b8601e2a7683d605f117477fa0c
push id111544
push usermak77@bonardo.net
push dateTue, 29 May 2018 16:03:07 +0000
reviewersadw
bugs1464328
milestone62.0a1
Bug 1464328 - Autofill urls to-the-next-slash is broken. r=adw MozReview-Commit-ID: Enysz2IQRIC
toolkit/components/places/UnifiedComplete.js
toolkit/components/places/tests/unifiedcomplete/test_autofill_urls.js
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -2052,19 +2052,34 @@ Search.prototype = {
       row.getResultByIndex(QUERYINDEX_ORIGIN_URL),
       row.getResultByIndex(QUERYINDEX_ORIGIN_FRECENCY)
     );
   },
 
   _addURLAutofillMatch(row) {
     let url = row.getResultByIndex(QUERYINDEX_URL_URL);
     let strippedURL = row.getResultByIndex(QUERYINDEX_URL_STRIPPED_URL);
+    // We autofill urls to-the-next-slash.
+    // http://mozilla.org/foo/bar/baz will be autofilled to:
+    //  - http://mozilla.org/f[oo/]
+    //  - http://mozilla.org/foo/b[ar/]
+    //  - http://mozilla.org/foo/bar/b[az]
+    let value;
+    let strippedURLIndex = url.indexOf(strippedURL);
+    let strippedPrefix = url.substr(0, strippedURLIndex);
+    let nextSlashIndex = url.indexOf("/", strippedURLIndex + strippedURL.length - 1);
+    if (nextSlashIndex == -1) {
+      value = url.substr(strippedURLIndex);
+    } else {
+      value = url.substring(strippedURLIndex, nextSlashIndex + 1);
+    }
+
     this._addAutofillMatch(
-      url.substr(url.indexOf(strippedURL)),
-      url,
+      value,
+      strippedPrefix + value,
       row.getResultByIndex(QUERYINDEX_URL_FRECENCY)
     );
   },
 
   _addAutofillMatch(autofilledValue, finalCompleteValue, frecency, extraStyles = []) {
     // The match's comment is only for display.  Set it to finalCompleteValue,
     // the actual URL that will be visited when the user chooses the match, so
     // that the user knows exactly where the match will take them.  To make it
--- a/toolkit/components/places/tests/unifiedcomplete/test_autofill_urls.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_autofill_urls.js
@@ -48,8 +48,48 @@ add_task(async function portNoMatch() {
     uri: "http://example.com:8888/foo",
   }]);
   await check_autocomplete({
     search: "example.com:8999/f",
     matches: [],
   });
   await cleanup();
 });
+
+// autofill to the next slash
+add_task(async function port() {
+  await PlacesTestUtils.addVisits([{
+    uri: "http://example.com:8888/foo/bar/baz",
+  }]);
+  await check_autocomplete({
+    search: "example.com:8888/foo/b",
+    autofilled: "example.com:8888/foo/bar/",
+    completed: "http://example.com:8888/foo/bar/",
+    matches: [{
+      value: "example.com:8888/foo/bar/",
+      comment: "example.com:8888/foo/bar/",
+      style: ["autofill", "heuristic"],
+    }, {
+      value: "http://example.com:8888/foo/bar/baz",
+      comment: "test visit for http://example.com:8888/foo/bar/baz",
+      style: ["favicon"],
+    }],
+  });
+  await cleanup();
+});
+
+// autofill to the next slash, end of url
+add_task(async function port() {
+  await PlacesTestUtils.addVisits([{
+    uri: "http://example.com:8888/foo/bar/baz",
+  }]);
+  await check_autocomplete({
+    search: "example.com:8888/foo/bar/b",
+    autofilled: "example.com:8888/foo/bar/baz",
+    completed: "http://example.com:8888/foo/bar/baz",
+    matches: [{
+      value: "example.com:8888/foo/bar/baz",
+      comment: "example.com:8888/foo/bar/baz",
+      style: ["autofill", "heuristic"],
+    }],
+  });
+  await cleanup();
+});