Skip to content

Commit

Permalink
Escape special whitespace characters in attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Feb 18, 2024
1 parent 33749d2 commit be3e366
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/js/static-filtering-parser.js
Expand Up @@ -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;
Expand All @@ -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; }
Expand Down

0 comments on commit be3e366

Please sign in to comment.