From be3e36601941ed69c911bf327333f2f5bed4c3ec Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 17 Feb 2024 19:57:44 -0500 Subject: [PATCH] Escape special whitespace characters in attribute values Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3127 Reference: https://mathiasbynens.be/notes/css-escapes --- src/js/static-filtering-parser.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index cc955c5f604d5..aa118c9dec198 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -3458,6 +3458,8 @@ class ExtSelectorCompiler { // https://github.com/uBlockOrigin/uBlock-issues/issues/2300 // Unquoted attribute values are parsed as Identifier instead of String. + // https://github.com/uBlockOrigin/uBlock-issues/issues/3127 + // Escape [\t\n\v\f\r] astSerializePart(part) { const out = []; const { data } = part; @@ -3473,7 +3475,14 @@ class ExtSelectorCompiler { if ( typeof value !== 'string' ) { value = data.value.name; } - value = value.replace(/["\\]/g, '\\$&'); + if ( /["\\]/.test(value) ) { + value = value.replace(/["\\]/g, '\\$&'); + } + if ( /[\x09-\x0D]/.test(value) ) { + value = value.replace(/[\x09-\x0D]/g, s => + `\\${s.charCodeAt(0).toString(16).toUpperCase()} ` + ); + } let flags = ''; if ( typeof data.flags === 'string' ) { if ( /^(is?|si?)$/.test(data.flags) === false ) { return; }