Redirect non-existing operators to a void operator

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2292

This will prevent unexpected oversezealous blocking if ever
this happens again. The internal void operator will ensure
no blocking takes place and issue a note about non-existing
operator to the dev tools console.
This commit is contained in:
Raymond Hill 2022-09-26 16:46:24 -04:00
parent a78bb0f8eb
commit 990ad75ca8
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -43,6 +43,14 @@ class PSelectorTask {
}
}
class PSelectorVoidTask extends PSelectorTask {
constructor(task) {
super();
console.info(`uBO: :${task[0]}() operator does not exist`);
}
transpose() {
}
}
class PSelectorHasTextTask extends PSelectorTask {
constructor(task) {
@ -377,8 +385,7 @@ class PSelector {
const tasks = [];
if ( Array.isArray(o.tasks) === false ) { return; }
for ( const task of o.tasks ) {
const ctor = this.operatorToTaskMap.get(task[0]);
if ( ctor === undefined ) { return; }
const ctor = this.operatorToTaskMap.get(task[0]) || PSelectorVoidTask;
tasks.push(new ctor(task));
}
// Initialize only after all tasks have been successfully instantiated