Skip to content

Commit be3e366

Browse files
committed
Escape special whitespace characters in attribute values
Related issue: uBlockOrigin/uBlock-issues#3127 Reference: https://mathiasbynens.be/notes/css-escapes
1 parent 33749d2 commit be3e366

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/js/static-filtering-parser.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3458,6 +3458,8 @@ class ExtSelectorCompiler {
34583458

34593459
// https://github.com/uBlockOrigin/uBlock-issues/issues/2300
34603460
// Unquoted attribute values are parsed as Identifier instead of String.
3461+
// https://github.com/uBlockOrigin/uBlock-issues/issues/3127
3462+
// Escape [\t\n\v\f\r]
34613463
astSerializePart(part) {
34623464
const out = [];
34633465
const { data } = part;
@@ -3473,7 +3475,14 @@ class ExtSelectorCompiler {
34733475
if ( typeof value !== 'string' ) {
34743476
value = data.value.name;
34753477
}
3476-
value = value.replace(/["\\]/g, '\\$&');
3478+
if ( /["\\]/.test(value) ) {
3479+
value = value.replace(/["\\]/g, '\\$&');
3480+
}
3481+
if ( /[\x09-\x0D]/.test(value) ) {
3482+
value = value.replace(/[\x09-\x0D]/g, s =>
3483+
`\\${s.charCodeAt(0).toString(16).toUpperCase()} `
3484+
);
3485+
}
34773486
let flags = '';
34783487
if ( typeof data.flags === 'string' ) {
34793488
if ( /^(is?|si?)$/.test(data.flags) === false ) { return; }

0 commit comments

Comments
 (0)