Bug 1280370 - Properly parse MatchPatterns with "data:" scheme r=mixedpuppy,zombie
authorRob Wu <rob@robwu.nl>
Tue, 24 Jul 2018 11:43:02 +0200
changeset 430598 587e951a256e672db6205e422b5ac5c26216773b
parent 430597 b4af8690942566c964ee6a11be297c556a17c423
child 430599 b6cb27b7a5791193f6fbae68cc338e20a767c34e
push id67542
push userrob@robwu.nl
push dateThu, 09 Aug 2018 02:00:24 +0000
treeherderautoland@72dd828f2481 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, zombie
bugs1280370
milestone63.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 1280370 - Properly parse MatchPatterns with "data:" scheme r=mixedpuppy,zombie The "data:" scheme is not followed by "//host". This patch fixes the parser so that "data:..." is expected instead of "data://...". MozReview-Commit-ID: 8TLVF3hdQ7H
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
@@ -322,21 +322,21 @@ MatchPattern::Init(JSContext* aCx, const
   }
 
   /***************************************************************************
    * Host
    ***************************************************************************/
   offset = index + 1;
   tail.Rebind(aPattern, offset);
 
-  if (scheme == nsGkAtoms::about) {
-    // about: URIs don't have hosts, so just treat the host as a wildcard and
-    // match on the path.
+  if (scheme == nsGkAtoms::about || scheme == nsGkAtoms::data) {
+    // about: and data: URIs don't have hosts, so just treat the host as a
+    // wildcard and match on the path.
     mMatchSubdomain = true;
-    // And so, ignorePath doesn't make sense for about: matchers.
+    // And so, ignorePath doesn't make sense for these matchers.
     aIgnorePath = false;
   } else {
     if (!StringHead(tail, 2).EqualsLiteral("//")) {
       aRv.Throw(NS_ERROR_INVALID_ARG);
       return;
     }
 
     offset += 2;
--- a/toolkit/components/extensions/test/xpcshell/test_MatchPattern.js
+++ b/toolkit/components/extensions/test/xpcshell/test_MatchPattern.js
@@ -107,30 +107,38 @@ add_task(async function test_MatchPatter
   pass({url: "http://mozilla.org", pattern: ["http://mozilla.org/"]});
   pass({url: "http://mozilla.org", pattern: ["http://mozilla.org/", "http://mozilla.com/"]});
   pass({url: "http://mozilla.com", pattern: ["http://mozilla.org/", "http://mozilla.com/"]});
   fail({url: "http://mozilla.biz", pattern: ["http://mozilla.org/", "http://mozilla.com/"]});
 
   // Match url with fragments.
   pass({url: "http://mozilla.org/base#some-fragment", pattern: "http://mozilla.org/base"});
 
+  // Match data:-URLs.
+  pass({url: "data:text/plain,foo", pattern: ["data:text/plain,foo"]});
+  pass({url: "data:text/plain,foo", pattern: ["data:text/plain,*"]});
+  pass({url: "data:text/plain;charset=utf-8,foo", pattern: ["data:text/plain;charset=utf-8,foo"]});
+  fail({url: "data:text/plain,foo", pattern: ["data:text/plain;charset=utf-8,foo"]});
+  fail({url: "data:text/plain;charset=utf-8,foo", pattern: ["data:text/plain,foo"]});
+
   // Privileged matchers:
   invalid({pattern: "about:foo"});
   invalid({pattern: "resource://foo/*"});
 
   pass({url: "about:foo", pattern: ["about:foo", "about:foo*"], options: {restrictSchemes: false}});
   pass({url: "about:foo", pattern: ["about:foo*"], options: {restrictSchemes: false}});
   pass({url: "about:foobar", pattern: ["about:foo*"], options: {restrictSchemes: false}});
 
   pass({url: "resource://foo/bar", pattern: ["resource://foo/bar"], options: {restrictSchemes: false}});
   fail({url: "resource://fog/bar", pattern: ["resource://foo/bar"], options: {restrictSchemes: false}});
   fail({url: "about:foo", pattern: ["about:meh"], options: {restrictSchemes: false}});
 
-  // about: matchers should ignore ignorePath.
+  // Matchers for schemes without host should ignore ignorePath.
   pass({url: "about:reader?http://e.com/", pattern: ["about:reader*"], options: {ignorePath: true, restrictSchemes: false}});
+  pass({url: "data:,", pattern: ["data:,*"], options: {ignorePath: true}});
 });
 
 add_task(async function test_MatchPattern_overlaps() {
   function test(filter, hosts, optional) {
     filter = Array.concat(filter);
     hosts = Array.concat(hosts);
     optional = Array.concat(optional);