1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-05 18:32:30 +01:00

Forbid multiple and unexpected CSS style declarations

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1806#issuecomment-963278382
This commit is contained in:
Raymond Hill 2021-11-08 11:17:47 -05:00
parent 1d099e07ae
commit 97232baee3
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -1437,12 +1437,17 @@ Parser.prototype.SelectorCompiler = class {
// https://github.com/uBlockOrigin/uBlock-issues/issues/1751
// Do not rely on matches() or querySelector() to test whether a
// selector is declarative or not.
// https://github.com/uBlockOrigin/uBlock-issues/issues/1806#issuecomment-963278382
// Forbid multiple and unexpected CSS style declarations.
sheetSelectable(s) {
if ( this.reSimpleSelector.test(s) ) { return true; }
if ( this.stylesheet === null ) { return true; }
try {
this.stylesheet.insertRule(`${s}{color:red}`);
if ( this.stylesheet.cssRules.length === 0 ) { return false; }
if ( this.stylesheet.cssRules.length !== 1 ) { return false; }
const style = this.stylesheet.cssRules[0].style;
if ( style.length !== 1 ) { return false; }
if ( style.getPropertyValue('color') !== 'red' ) { return false; }
this.stylesheet.deleteRule(0);
} catch (ex) {
return false;