Bug 666706 - Don't pass IPv6 literals to the effective TLD service, since the brackets prevent them from being recognized as IPs. r=gavin
authorDão Gottwald <dao@mozilla.com>
Sat, 25 Jun 2011 09:41:31 +0200
changeset 71691 a8b1330b8ac90438340562cd10f5da9e28ffcd65
parent 71690 b7439d5baf498cfe625ba8b7b4af1ebc2bb39dae
child 71692 dd2361d3b3f5a644c8eb0df55737d8478f4a7e68
push id20599
push userdgottwald@mozilla.com
push dateSat, 25 Jun 2011 07:42:50 +0000
treeherdermozilla-central@a8b1330b8ac9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs666706
milestone7.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 666706 - Don't pass IPv6 literals to the effective TLD service, since the brackets prevent them from being recognized as IPs. r=gavin
browser/base/content/test/browser_urlHighlight.js
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/test/browser_urlHighlight.js
+++ b/browser/base/content/test/browser_urlHighlight.js
@@ -58,20 +58,45 @@ function test() {
   testVal("<https://>mozilla.org</sub/file.ext>");
   testVal("<https://>mozilla.org</sub/file.ext?foo>");
   testVal("<https://>mozilla.org</sub/file.ext?foo&bar>");
   testVal("<https://>mozilla.org</sub/file.ext?foo&bar#top>");
   testVal("<https://>mozilla.org</sub/file.ext?foo&bar#top>");
 
   testVal("<https://sub.>mozilla.org<:666/file.ext>");
 
-  testVal("<https://>[fe80::222:19ff:fe11:8c76]</file.ext>");
-  testVal("[fe80::222:19ff:fe11:8c76]</file.ext>");
-  testVal("<https://user:pass@>[fe80::222:19ff:fe11:8c76]<:666/file.ext>");
-  testVal("<http://user:pass@>[fe80::222:19ff:fe11:8c76]<:666/file.ext>");
+  let IPs = ["192.168.1.1",
+             "[::]",
+             "[::1]",
+             "[1::]",
+             "[::]",
+             "[::1]",
+             "[1::]",
+             "[1:2:3:4:5:6:7::]",
+             "[::1:2:3:4:5:6:7]",
+             "[1:2:a:B:c:D:e:F]",
+             "[1::8]",
+             "[1:2::8]",
+             "[fe80::222:19ff:fe11:8c76]",
+             "[0000:0123:4567:89AB:CDEF:abcd:ef00:0000]",
+             "[::192.168.1.1]",
+             "[1::0.0.0.0]",
+             "[1:2::255.255.255.255]",
+             "[1:2:3::255.255.255.255]",
+             "[1:2:3:4::255.255.255.255]",
+             "[1:2:3:4:5::255.255.255.255]",
+             "[1:2:3:4:5:6:255.255.255.255]"];
+  IPs.forEach(function (IP) {
+    testVal(IP);
+    testVal(IP + "</file.ext>");
+    testVal("<https://>" + IP);
+    testVal("<https://>" + IP + "</file.ext>");
+    testVal("<https://user:pass@>" + IP + "<:666/file.ext>");
+    testVal("<http://user:pass@>" + IP + "<:666/file.ext>");
+  });
 
   testVal("mailto:admin@mozilla.org");
   testVal("gopher://mozilla.org/");
   testVal("about:config");
   testVal("jar:http://mozilla.org/example.jar!/");
   testVal("view-source:http://mozilla.org/");
   testVal("foo9://mozilla.org/");
   testVal("foo+://mozilla.org/");
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -207,22 +207,28 @@
               ["http:", "https:", "ftp:"].indexOf(protocol[0]) == -1)
             return;
           let matchedURL = value.match(/^((?:[a-z]+:\/\/)?(?:[^\/]+@)?)(.+?)(?::\d+)?(?:\/|$)/);
           if (!matchedURL)
             return;
 
           let [, preDomain, domain] = matchedURL;
           let baseDomain = domain;
-          try {
-            baseDomain = Services.eTLD.getBaseDomainFromHost(domain);
-          } catch (e) {}
-          let segments = function (s) s.replace(/[^.]*/g, "").length + 1;
-          let subSegments = segments(domain) - segments(baseDomain);
-          let subDomain = domain.match(new RegExp("(?:[^.]*\.){" + subSegments + "}"))[0];
+          let subDomain = "";
+          // getBaseDomainFromHost doesn't recognize IPv6 literals in brackets as IPs (bug 667159)
+          if (domain[0] != "[") {
+            try {
+              baseDomain = Services.eTLD.getBaseDomainFromHost(domain);
+            } catch (e) {}
+          }
+          if (baseDomain != domain) {
+            let segments = function (s) s.replace(/[^.]*/g, "").length + 1;
+            let subSegments = segments(domain) - segments(baseDomain);
+            subDomain = domain.match(new RegExp("(?:[^.]*\.){" + subSegments + "}"))[0];
+          }
 
           let rangeLength = preDomain.length + subDomain.length;
           if (rangeLength) {
             let range = document.createRange();
             range.setStart(textNode, 0);
             range.setEnd(textNode, rangeLength);
             selection.addRange(range);
           }