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
1 changed files with 5 additions and 2 deletions

View File

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