Bug 1537640 - Properly autofill partial IPs in the address bar. r=adw a=pascalc
authorMarco Bonardo <mbonardo@mozilla.com>
Sat, 23 Mar 2019 00:12:21 +0000
changeset 525748 d86ab22b61a1f8bf3cc1484deb69a24f0bef6578
parent 525747 d5a9d2da215fe31f734b047cdfdb12fbc5afd732
child 525749 0feaf41d4e517439650f4f751a3df0d234d4971d
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, pascalc
bugs1537640
milestone67.0
Bug 1537640 - Properly autofill partial IPs in the address bar. r=adw a=pascalc Trying to autofill as urls breaks our assumptions. Differential Revision: https://phabricator.services.mozilla.com/D24572
browser/components/urlbar/UrlbarTokenizer.jsm
toolkit/components/places/tests/unifiedcomplete/test_autofill_origins.js
--- a/browser/components/urlbar/UrlbarTokenizer.jsm
+++ b/browser/components/urlbar/UrlbarTokenizer.jsm
@@ -26,19 +26,22 @@ var UrlbarTokenizer = {
 
   // Regex used to guess url-like strings.
   // These are not expected to be 100% correct, we accept some user mistypes
   // and we're unlikely to be able to cover 100% of the cases.
   REGEXP_LIKE_PROTOCOL: /^[A-Z+.-]+:\/{0,2}(?!\/)/i,
   REGEXP_USERINFO_INVALID_CHARS: /[^\w.~%!$&'()*+,;=:-]/,
   REGEXP_HOSTPORT_INVALID_CHARS: /[^\[\]A-Z0-9.:-]/i,
   REGEXP_HOSTPORT_IP_LIKE: /^[a-f0-9\.\[\]:]+$/i,
-  REGEXP_HOSTPORT_INVALID_IP: /\.{2,}|\d{5,}|\d{4,}(?![:\]])|^\.|\.$|^(\d+\.){4,}\d+$|^\d+$/,
+  // This accepts partial IPv4.
+  REGEXP_HOSTPORT_INVALID_IP: /\.{2,}|\d{5,}|\d{4,}(?![:\]])|^\.|^(\d+\.){4,}\d+$|^\d{4,}$/,
+  // This only accepts complete IPv4.
   REGEXP_HOSTPORT_IPV4: /^(\d{1,3}\.){3,}\d{1,3}(:\d+)?$/,
-  REGEXP_HOSTPORT_IPV6: /^[0-9A-F:\[\]]{1,4}$/i,
+  // This accepts partial IPv6.
+  REGEXP_HOSTPORT_IPV6: /^\[([0-9a-f]{0,4}:){0,7}[0-9a-f]{0,4}\]?$/i,
   REGEXP_COMMON_EMAIL: /^[\w!#$%&'*+\/=?^`{|}~-]+@[\[\]A-Z0-9.-]+$/i,
 
   TYPE: {
     TEXT: 1,
     POSSIBLE_ORIGIN: 2, // It may be an ip, a domain, but even just a single word used as host.
     POSSIBLE_URL: 3, // Consumers should still check this with a fixup.
     RESTRICT_HISTORY: 4,
     RESTRICT_BOOKMARK: 5,
--- a/toolkit/components/places/tests/unifiedcomplete/test_autofill_origins.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_autofill_origins.js
@@ -168,16 +168,41 @@ add_task(async function multidotted() {
       value: "www.example.co.jp:8888/",
       comment: "www.example.co.jp:8888",
       style: ["autofill", "heuristic"],
     }],
   });
   await cleanup();
 });
 
+add_task(async function test_ip() {
+  for (let str of [
+    "192.168.1.1/",
+    "255.255.255.255:8080/",
+    "[2001:db8::1428:57ab]/",
+    "[::c0a8:5909]/",
+    "[::1]/",
+  ]) {
+    info("testing " + str);
+    await PlacesTestUtils.addVisits("http://" + str);
+    for (let i = 1; i < str.length; ++i) {
+      await check_autocomplete({
+        search: str.substring(0, i),
+        completed: "http://" + str,
+        matches: [{
+          value: str,
+          comment: str.replace(/\/$/, ""), // strip trailing slash
+          style: ["autofill", "heuristic"],
+        }],
+      });
+    }
+    await cleanup();
+  }
+});
+
 // When determining which origins should be autofilled, all the origins sharing
 // a host should be added together to get their combined frecency -- i.e.,
 // prefixes should be collapsed.  And then from that list, the origin with the
 // highest frecency should be chosen.
 add_task(async function groupByHost() {
   // Add some visits to the same host, example.com.  Add one http and two https
   // so that https has a higher frecency and is therefore the origin that should
   // be autofilled.  Also add another origin that has a higher frecency than