Bug 1302004 - go back to relying on the asciiHost instead of the input when determining whether to show an info bar, as it more reliably corresponds to the host only in expressions like 123/2, r=jaws
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 13 Sep 2016 14:44:13 +0100
changeset 314138 fd2adbce4fafd6de87b507656b0ae38ae6c55763
parent 314137 5ac7de63360948e4e7979ad483a2214e2c3fd472
child 314139 ef7939c0332eb73be104210509dd45488f03dc3e
push id30708
push usercbook@mozilla.com
push dateFri, 16 Sep 2016 10:52:07 +0000
treeherdermozilla-central@3172114c06cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1302004
milestone51.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 1302004 - go back to relying on the asciiHost instead of the input when determining whether to show an info bar, as it more reliably corresponds to the host only in expressions like 123/2, r=jaws The patch uses a combination of IPv4 detection and the existing regexp check, for reasons outlined in the patch. The network-level normalization for URIs catches some of the numbers-only IP requests, but not all of them. MozReview-Commit-ID: AS02rs2b2NP
browser/base/content/browser.js
browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -685,18 +685,36 @@ function gKeywordURIFixup({ target: brow
   // Normalize out a single trailing dot - NB: not using endsWith/lastIndexOf
   // because we need to be sure this last dot is the *only* dot, too.
   // More generally, this is used for the pref and should stay in sync with
   // the code in nsDefaultURIFixup::KeywordURIFixup .
   if (asciiHost.indexOf('.') == asciiHost.length - 1) {
     asciiHost = asciiHost.slice(0, -1);
   }
 
-  // Ignore number-only things entirely (no decimal IPs for you!)
-  if (/^\d+$/.test(fixupInfo.originalInput.trim()))
+  let isIPv4Address = host => {
+    let parts = host.split(".");
+    if (parts.length != 4) {
+      return false;
+    }
+    return parts.every(part => {
+      let n = parseInt(part, 10);
+      return n >= 0 && n <= 255;
+    });
+  };
+  // Avoid showing fixup information if we're suggesting an IP. Note that
+  // decimal representations of IPs are normalized to a 'regular'
+  // dot-separated IP address by network code, but that only happens for
+  // numbers that don't overflow. Longer numbers do not get normalized,
+  // but still work to access IP addresses. So for instance,
+  // 1097347366913 (ff7f000001) gets resolved by using the final bytes,
+  // making it the same as 7f000001, which is 127.0.0.1 aka localhost.
+  // While 2130706433 would get normalized by network, 1097347366913
+  // does not, and we have to deal with both cases here:
+  if (isIPv4Address(asciiHost) || /^\d+$/.test(asciiHost))
     return;
 
   let onLookupComplete = (request, record, status) => {
     let browser = weakBrowser.get();
     if (!Components.isSuccessCode(status) || !browser)
       return;
 
     let currentURI = browser.currentURI;
--- a/browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js
+++ b/browser/base/content/test/urlbar/browser_urlbarSearchSingleWordNotification.js
@@ -6,19 +6,19 @@
 var notificationObserver;
 registerCleanupFunction(function() {
   Services.prefs.clearUserPref("browser.fixup.domainwhitelist.localhost");
   if (notificationObserver) {
     notificationObserver.disconnect();
   }
 });
 
-function promiseNotificationForTab(aBrowser, value, expected, tab=aBrowser.selectedTab) {
+function promiseNotification(aBrowser, value, expected, input) {
   let deferred = Promise.defer();
-  let notificationBox = aBrowser.getNotificationBox(tab.linkedBrowser);
+  let notificationBox = aBrowser.getNotificationBox(aBrowser.selectedBrowser);
   if (expected) {
     info("Waiting for " + value + " notification");
     let checkForNotification = function() {
       if (notificationBox.getNotificationWithValue(value)) {
         info("Saw the notification");
         notificationObserver.disconnect();
         notificationObserver = null;
         deferred.resolve();
@@ -26,17 +26,18 @@ function promiseNotificationForTab(aBrow
     }
     if (notificationObserver) {
       notificationObserver.disconnect();
     }
     notificationObserver = new MutationObserver(checkForNotification);
     notificationObserver.observe(notificationBox, {childList: true});
   } else {
     setTimeout(() => {
-      is(notificationBox.getNotificationWithValue(value), null, "We are expecting to not get a notification");
+      is(notificationBox.getNotificationWithValue(value), null,
+         `We are expecting to not get a notification for ${input}`);
       deferred.resolve();
     }, 1000);
   }
   return deferred.promise;
 }
 
 function* runURLBarSearchTest({valueToOpen, expectSearch, expectNotification, aWindow=window}) {
   aWindow.gURLBar.value = valueToOpen;
@@ -50,17 +51,17 @@ function* runURLBarSearchTest({valueToOp
     expectedURI = Services.search.defaultEngine.getSubmission(valueToOpen, null, "keyword").uri.spec;
   }
   aWindow.gURLBar.focus();
   let docLoadPromise = waitForDocLoadAndStopIt(expectedURI, aWindow.gBrowser.selectedBrowser);
   EventUtils.synthesizeKey("VK_RETURN", {}, aWindow);
 
   yield Promise.all([
     docLoadPromise,
-    promiseNotificationForTab(aWindow.gBrowser, "keyword-uri-fixup", expectNotification)
+    promiseNotification(aWindow.gBrowser, "keyword-uri-fixup", expectNotification, valueToOpen)
   ]);
 }
 
 add_task(function* test_navigate_full_domain() {
   let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
   yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
   yield* runURLBarSearchTest({
     valueToOpen: "www.mozilla.org",
@@ -76,16 +77,27 @@ add_task(function* test_navigate_decimal
   yield* runURLBarSearchTest({
     valueToOpen: "1234",
     expectSearch: true,
     expectNotification: false,
   });
   gBrowser.removeTab(tab);
 });
 
+add_task(function* test_navigate_decimal_ip_with_path() {
+  let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
+  yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+  yield* runURLBarSearchTest({
+    valueToOpen: "1234/12",
+    expectSearch: true,
+    expectNotification: false,
+  });
+  gBrowser.removeTab(tab);
+});
+
 add_task(function* test_navigate_large_number() {
   let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
   yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
   yield* runURLBarSearchTest({
     valueToOpen: "123456789012345",
     expectSearch: true,
     expectNotification: false
   });