Bug 1529230 - Drop bracket for IPv6 URL in mDomain of MatchPattern. r=robwu,mixedpuppy
authorviolet <violet.bugreport@gmail.com>
Sat, 02 Mar 2019 13:20:10 +0000
changeset 520059 325cacd860797a527eddfb6652984169a3882523
parent 520058 9506816277411c422b23f1b74b2e058dda615d6d
child 520066 0d261741c46150c46144dd5ef382d57e40e45279
child 520067 eb002115d6be1e8a06b3f97c717b90a55e39c441
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobwu, mixedpuppy
bugs1529230
milestone67.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 1529230 - Drop bracket for IPv6 URL in mDomain of MatchPattern. r=robwu,mixedpuppy mDomain in MatchPattern is inconsistent with nsIURI for IPv6 URL, which causes failure of IPv6 matching. We normalize mDomain by droping the brackets so that it's consistent with nsIURI. Differential Revision: https://phabricator.services.mozilla.com/D20603
toolkit/components/extensions/MatchPattern.cpp
toolkit/components/extensions/test/xpcshell/test_MatchPattern.js
--- a/toolkit/components/extensions/MatchPattern.cpp
+++ b/toolkit/components/extensions/MatchPattern.cpp
@@ -319,16 +319,21 @@ void MatchPattern::Init(JSContext* aCx, 
     offset += index;
     tail.Rebind(aPattern, offset);
 
     if (host.EqualsLiteral("*")) {
       mMatchSubdomain = true;
     } else if (StringHead(host, 2).EqualsLiteral("*.")) {
       mDomain = NS_ConvertUTF16toUTF8(Substring(host, 2));
       mMatchSubdomain = true;
+    } else if (host.Length() > 1 && host[0] == '[' &&
+               host[host.Length() - 1] == ']') {
+      // This is an IPv6 literal, we drop the enclosing `[]` to be
+      // consistent with nsIURI.
+      mDomain = NS_ConvertUTF16toUTF8(Substring(host, 1, host.Length() - 2));
     } else {
       mDomain = NS_ConvertUTF16toUTF8(host);
     }
   }
 
   /***************************************************************************
    * Path
    ***************************************************************************/
--- a/toolkit/components/extensions/test/xpcshell/test_MatchPattern.js
+++ b/toolkit/components/extensions/test/xpcshell/test_MatchPattern.js
@@ -153,16 +153,26 @@ add_task(async function test_MatchPatter
   pass({url: "unknown-scheme:foo", pattern: ["unknown-scheme:foo"], options: {restrictSchemes: false}});
   pass({url: "unknown-scheme:foo", pattern: ["unknown-scheme:*"], options: {restrictSchemes: false}});
   pass({url: "unknown-scheme://foo", pattern: ["unknown-scheme://foo"], options: {restrictSchemes: false}});
   pass({url: "unknown-scheme://foo", pattern: ["unknown-scheme://*"], options: {restrictSchemes: false}});
   pass({url: "unknown-scheme://foo", pattern: ["unknown-scheme:*"], options: {restrictSchemes: false}});
   fail({url: "unknown-scheme://foo", pattern: ["unknown-scheme:foo"], options: {restrictSchemes: false}});
   fail({url: "unknown-scheme:foo", pattern: ["unknown-scheme://foo"], options: {restrictSchemes: false}});
   fail({url: "unknown-scheme:foo", pattern: ["unknown-scheme://*"], options: {restrictSchemes: false}});
+
+  // Matchers for IPv6
+  pass({url: "http://[::1]/", pattern: ["http://[::1]/"]});
+  pass({url: "http://[2a03:4000:6:310e:216:3eff:fe53:99b]/", pattern: ["http://[2a03:4000:6:310e:216:3eff:fe53:99b]/"]});
+  fail({url: "http://[2:4:6:3:2:3:f:b]/", pattern: ["http://[2a03:4000:6:310e:216:3eff:fe53:99b]/"]});
+
+  // Before fixing Bug 1529230, the only way to match a specific IPv6 url is by droping the brackets in pattern,
+  // thus we keep this pattern valid for the sake of backward compatibility
+  pass({url: "http://[::1]/", pattern: ["http://::1/"]});
+  pass({url: "http://[2a03:4000:6:310e:216:3eff:fe53:99b]/", pattern: ["http://2a03:4000:6:310e:216:3eff:fe53:99b/"]});
 });
 
 add_task(async function test_MatchPattern_overlaps() {
   function test(filter, hosts, optional) {
     filter = Array.concat(filter);
     hosts = Array.concat(hosts);
     optional = Array.concat(optional);