зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1217944 - Part 1 - Make MatchGlobs work on arbitrary strings r=kmag
MozReview-Commit-ID: CK39lpGglKA --HG-- extra : transplant_source : m%0C%D4%E0W%00%0F%00%D05%1E%8D%D8%91%C2%218nFB
This commit is contained in:
Родитель
5a889e729a
Коммит
8aa15a9f8c
|
@ -170,12 +170,12 @@ Script.prototype = {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -175,6 +175,7 @@ MatchPattern.prototype = {
|
|||
|
||||
// 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 {
|
||||
|
@ -183,13 +184,10 @@ this.MatchGlobs = function(globs) {
|
|||
};
|
||||
|
||||
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;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@ 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}) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче