Better validate :upward() argument

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2442#issuecomment-1371484554
This commit is contained in:
Raymond Hill 2023-01-05 08:39:31 -05:00
parent 3e85e51dd2
commit 7b8c096270
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -1587,15 +1587,8 @@ Parser.prototype.SelectorCompiler = class {
break;
case 'not': {
if ( this.astHasType(args, 'Combinator', 0) === false ) { break; }
const selectors = this.astSelectorsFromSelectorList(args);
if ( Array.isArray(selectors) === false || selectors.length === 0 ) {
if ( this.astIsValidSelectorList(args) !== true ) {
data.type = 'Error';
break;
}
for ( const selector of selectors ) {
if ( this.astIsValidSelector(selector) ) { continue; }
data.type = 'Error';
break;
}
break;
}
@ -1865,6 +1858,17 @@ Parser.prototype.SelectorCompiler = class {
return true;
}
astIsValidSelectorList(args) {
const selectors = this.astSelectorsFromSelectorList(args);
if ( Array.isArray(selectors) === false || selectors.length === 0 ) {
return false;
}
for ( const selector of selectors ) {
if ( this.astIsValidSelector(selector) !== true ) { return false; }
}
return true;
}
translateAdguardCSSInjectionFilter(suffix) {
const matches = /^(.*)\s*\{([^}]+)\}\s*$/.exec(suffix);
if ( matches === null ) { return ''; }
@ -2071,6 +2075,7 @@ Parser.prototype.SelectorCompiler = class {
const i = this.compileInteger(s, 1, 256);
if ( i !== undefined ) { return i; }
const parts = this.astFromRaw(s, 'selectorList' );
if ( this.astIsValidSelectorList(parts) !== true ) { return; }
if ( this.astHasType(parts, 'ProceduralSelector') ) { return; }
if ( this.astHasType(parts, 'ActionSelector') ) { return; }
if ( this.astHasType(parts, 'Error') ) { return; }