From 24273d2c948edc3c83135cbdad68152e504dbed2 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 4 Oct 2022 08:11:31 -0400 Subject: [PATCH] Escape attribute values Related issues: - https://github.com/uBlockOrigin/uBlock-issues/issues/2284#issuecomment-1265417399 --- src/js/codemirror/ubo-static-filtering.js | 5 ++++- src/js/static-filtering-parser.js | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index 645879ace..bea589d9d 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -40,7 +40,10 @@ let hintHelperRegistered = false; CodeMirror.defineMode('ubo-static-filtering', function() { if ( StaticFilteringParser instanceof Object === false ) { return; } - const parser = new StaticFilteringParser({ interactive: true }); + const parser = new StaticFilteringParser({ + interactive: true, + nativeCssHas: vAPI.webextFlavor.env.includes('native_css_has'), + }); const reURL = /\bhttps?:\/\/\S+/; const rePreparseDirectives = /^!#(?:if|endif|include )\b/; diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index e0fc68ea8..0778183ea 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1586,7 +1586,7 @@ Parser.prototype.SelectorCompiler = class { if ( typeof value !== 'string' ) { value = data.value.name; } - out.push(`[${name}${data.matcher}"${value}"]`); + out.push(`[${name}${data.matcher}"${CSS.escape(value)}"]`); break; } case 'ClassSelector': @@ -1858,6 +1858,7 @@ Parser.prototype.SelectorCompiler = class { // backslash characters. // Remove potentially present quotes before processing. compileText(s) { + if ( s === '' ) { return; } s = this.extractArg(s); const match = this.reParseRegexLiteral.exec(s); let regexDetails; @@ -1950,6 +1951,7 @@ Parser.prototype.SelectorCompiler = class { } compileAttrList(s) { + if ( s === '' ) { return; } const attrs = s.split('\s*,\s*'); const out = []; for ( const attr of attrs ) {