From 990ad75ca8a45805495160fe99d3af8d4c9afeeb Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 26 Sep 2022 16:46:24 -0400 Subject: [PATCH] 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. --- src/js/contentscript-extra.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/js/contentscript-extra.js b/src/js/contentscript-extra.js index 8a48b3d7a60f7..11cbc595a24ca 100644 --- a/src/js/contentscript-extra.js +++ b/src/js/contentscript-extra.js @@ -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