1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 01:27:12 +02:00

Escape special whitespace characters in attribute values

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/3127

Reference:
https://mathiasbynens.be/notes/css-escapes
This commit is contained in:
Raymond Hill 2024-02-17 19:57:44 -05:00
parent 33749d2d3f
commit be3e366019
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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; }