Bug 1217944 Part 1 Make MatchGlobs work on arbitrary strings r?kmag draft
authorAndrew Swan <aswan@mozilla.com>
Wed, 06 Apr 2016 13:07:47 -0700
changeset 348171 6d0cd4e057000f00d0351e8dd891c221386e4642
parent 347827 d24f23b9b8a14ea2b9f9e55f1b8736e65b2c08fa
child 348172 5408a4e33201a9912558951464551bbd64d93785
push id14765
push useraswan@mozilla.com
push dateWed, 06 Apr 2016 20:21:59 +0000
reviewerskmag
bugs1217944
milestone48.0a1
Bug 1217944 Part 1 Make MatchGlobs work on arbitrary strings r?kmag MozReview-Commit-ID: CK39lpGglKA
toolkit/components/extensions/ExtensionContent.jsm
toolkit/modules/addons/MatchPattern.jsm
toolkit/modules/tests/xpcshell/test_MatchGlobs.js
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -165,22 +165,22 @@ Script.prototype = {
       return false;
     }
 
     if (this.exclude_matches_.matches(uri)) {
       return false;
     }
 
     if (this.options.include_globs != null) {
-      if (!this.include_globs_.matches(uri)) {
+      if (!this.include_globs_.matches(uri.spec)) {
         return false;
       }
     }
 
-    if (this.exclude_globs_.matches(uri)) {
+    if (this.exclude_globs_.matches(uri.spec)) {
       return false;
     }
 
     if (this.options.frame_id != null) {
       if (WebNavigationFrames.getFrameId(window) != this.options.frame_id) {
         return false;
       }
     } else if (!this.options.all_frames && window.top != window) {
--- a/toolkit/modules/addons/MatchPattern.jsm
+++ b/toolkit/modules/addons/MatchPattern.jsm
@@ -170,26 +170,24 @@ MatchPattern.prototype = {
 
   serialize() {
     return this.pat;
   },
 };
 
 // Globs can match everything. Be careful, this DOES NOT filter by allowed schemes!
 this.MatchGlobs = function(globs) {
+  this.original = globs;
   if (globs) {
     this.regexps = Array.from(globs, (glob) => globToRegexp(glob, true));
   } else {
     this.regexps = [];
   }
 };
 
 MatchGlobs.prototype = {
-  matches(uri) {
-    let spec = uri.spec;
-    for (let regexp of this.regexps) {
-      if (regexp.test(spec)) {
-        return true;
-      }
-    }
-    return false;
+  matches(str) {
+    return this.regexps.some(regexp => regexp.test(str));
+  },
+  serialize() {
+    return this.original;
   },
 };
--- a/toolkit/modules/tests/xpcshell/test_MatchGlobs.js
+++ b/toolkit/modules/tests/xpcshell/test_MatchGlobs.js
@@ -4,17 +4,17 @@
 "use strict";
 
 Components.utils.import("resource://gre/modules/MatchPattern.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 function test(url, pattern) {
   let uri = Services.io.newURI(url, null, null);
   let m = new MatchGlobs(pattern);
-  return m.matches(uri);
+  return m.matches(uri.spec);
 }
 
 function pass({url, pattern}) {
   ok(test(url, pattern), `Expected match: ${JSON.stringify(pattern)}, ${url}`);
 }
 
 function fail({url, pattern}) {
   ok(!test(url, pattern), `Expected no match: ${JSON.stringify(pattern)}, ${url}`);