Bug 1304826 - Expanded the regexp so that large hex numbers are not recognized as IP address. r?Gijs
MozReview-Commit-ID: IwQMyYj6D5Z
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -704,17 +704,17 @@ function gKeywordURIFixup({ target: brow
// 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))
+ if (isIPv4Address(asciiHost) || /^(?:\d+|0x[a-f0-9]+)$/i.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
@@ -98,16 +98,39 @@ add_task(function* test_navigate_large_n
yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
yield* runURLBarSearchTest({
valueToOpen: "123456789012345",
expectSearch: true,
expectNotification: false
});
gBrowser.removeTab(tab);
});
+
+add_task(function* test_navigate_small_hex_number() {
+ let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
+ yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ yield* runURLBarSearchTest({
+ valueToOpen: "0x1f00ffff",
+ expectSearch: true,
+ expectNotification: false
+ });
+ gBrowser.removeTab(tab);
+});
+
+add_task(function* test_navigate_large_hex_number() {
+ let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
+ yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ yield* runURLBarSearchTest({
+ valueToOpen: "0x7f0000017f000001",
+ expectSearch: true,
+ expectNotification: false
+ });
+ gBrowser.removeTab(tab);
+});
+
function get_test_function_for_localhost_with_hostname(hostName, isPrivate) {
return function* test_navigate_single_host() {
const pref = "browser.fixup.domainwhitelist.localhost";
let win;
if (isPrivate) {
win = yield promiseOpenAndLoadWindow({private: true}, true);
let deferredOpenFocus = Promise.defer();
waitForFocus(deferredOpenFocus.resolve, win);