mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-11 09:31:01 +01:00
code review: fix recursivity in HTML filtering's procedural selectors
This commit is contained in:
parent
31791f2dd2
commit
707d7708a1
1 changed files with 25 additions and 2 deletions
|
@ -62,6 +62,11 @@
|
|||
this.pselector = new PSelector(task[1]);
|
||||
};
|
||||
PSelectorIfTask.prototype.target = true;
|
||||
Object.defineProperty(PSelectorIfTask.prototype, 'invalid', {
|
||||
get: function() {
|
||||
return this.pselector.invalid;
|
||||
}
|
||||
});
|
||||
PSelectorIfTask.prototype.exec = function(input) {
|
||||
var output = [];
|
||||
for ( var node of input ) {
|
||||
|
@ -113,7 +118,6 @@
|
|||
[ ':xpath', PSelectorXpathTask ]
|
||||
]);
|
||||
}
|
||||
this.invalid = false;
|
||||
this.raw = o.raw;
|
||||
this.selector = o.selector;
|
||||
this.tasks = [];
|
||||
|
@ -125,10 +129,16 @@
|
|||
this.invalid = true;
|
||||
break;
|
||||
}
|
||||
this.tasks.push(new ctor(task));
|
||||
var pselector = new ctor(task);
|
||||
if ( pselector instanceof PSelectorIfTask && pselector.invalid ) {
|
||||
this.invalid = true;
|
||||
break;
|
||||
}
|
||||
this.tasks.push(pselector);
|
||||
}
|
||||
};
|
||||
PSelector.prototype.operatorToTaskMap = undefined;
|
||||
PSelector.prototype.invalid = false;
|
||||
PSelector.prototype.prime = function(input) {
|
||||
var root = input || docRegister;
|
||||
if ( this.selector !== '' ) {
|
||||
|
@ -145,6 +155,19 @@
|
|||
}
|
||||
return nodes;
|
||||
};
|
||||
PSelector.prototype.test = function(input) {
|
||||
if ( this.invalid ) { return false; }
|
||||
var nodes = this.prime(input), AA = [ null ], aa;
|
||||
for ( var node of nodes ) {
|
||||
AA[0] = node; aa = AA;
|
||||
for ( var task of this.tasks ) {
|
||||
aa = task.exec(aa);
|
||||
if ( aa.length === 0 ) { break; }
|
||||
}
|
||||
if ( aa.length !== 0 ) { return true; }
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
var logOne = function(details, selector) {
|
||||
loggerRegister.writeOne(
|
||||
|
|
Loading…
Reference in a new issue