Bug 1217944 Part 1 Make MatchGlobs work on arbitrary strings r?kmag
MozReview-Commit-ID: CK39lpGglKA
--- 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}`);