1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-04 10:09:38 +02:00

Forbid relative selector at top level

Related commit:
- a71b71e4c8
This commit is contained in:
Raymond Hill 2022-09-25 08:51:48 -04:00
parent 6828e1c3b2
commit 59aa235952
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -1336,7 +1336,7 @@ Parser.prototype.SelectorCompiler = class {
`${cssClassOrId}(?:${cssClassOrId})*(?:${cssAttribute})*` + '|' +
`${cssAttribute}(?:${cssAttribute})*` +
')';
const cssCombinator = '(?:\\s+|\\s*[>+~]\\s*)';
const cssCombinator = '(?:\\s+|\\s*[+>~]\\s*)';
this.reCommonSelector = new RegExp(
`^${cssSimple}(?:${cssCombinator}${cssSimple})*$`
);
@ -1386,6 +1386,7 @@ Parser.prototype.SelectorCompiler = class {
[ 'contains', 'has-text' ],
[ 'has', 'has' ],
]);
this.reIsRelativeSelector = /^\s*[+>~]/;
this.reExtendedSyntax = /\[-(?:abp|ext)-[a-z-]+=(['"])(?:.+?)(?:\1)\]/;
this.reExtendedSyntaxReplacer = /\[-(?:abp|ext)-([a-z-]+)=(['"])(.+?)\2\]/g;
this.abpProceduralOpReplacer = /:-abp-(?:contains|has)\(/g;
@ -1430,6 +1431,9 @@ Parser.prototype.SelectorCompiler = class {
}
}
// Relative selectors not allowed at top level.
if ( this.reIsRelativeSelector.test(raw) ) { return false; }
if ( this.reCommonSelector.test(raw) ) {
out.compiled = raw;
return true;
@ -1442,7 +1446,6 @@ Parser.prototype.SelectorCompiler = class {
out.compiled.raw = raw;
out.compiled = JSON.stringify(out.compiled);
}
return true;
}