From 93953f9b211f745da614b694b8fe380759fcf771 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 6 Oct 2022 16:57:03 -0400 Subject: [PATCH] Prepend attribute flags with space Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/issues/2310#issuecomment-1269001494 --- src/js/static-filtering-parser.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 36c5d650b..c4bc49095 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1391,7 +1391,7 @@ Parser.prototype.SelectorCompiler = class { this.nativeCssHas = instanceOptions.nativeCssHas === true; // https://www.w3.org/TR/css-syntax-3/#typedef-ident-token - this.reValidIdentifier = /^\*|-?[A-Za-z_\xC0-\xFF\\\-]/; + this.reInvalidIdentifier = /^\d/; } compile(raw, out, compileOptions = {}) { @@ -1579,7 +1579,7 @@ Parser.prototype.SelectorCompiler = class { switch ( data.type ) { case 'AttributeSelector': { const name = data.name.name; - if ( this.reValidIdentifier.test(name) === false ) { return; } + if ( this.reInvalidIdentifier.test(name) ) { return; } if ( data.matcher === null ) { out.push(`[${name}]`); break; @@ -1591,25 +1591,25 @@ Parser.prototype.SelectorCompiler = class { value = value.replace(/"/g, '\\$&'); let flags = ''; if ( typeof data.flags === 'string' ) { - flags = data.flags; - if ( /^(i|s|is|si)$/.test(flags) === false ) { return; } + if ( /^(is?|si?)$/.test(data.flags) === false ) { return; } + flags = ` ${data.flags}`; } out.push(`[${name}${data.matcher}"${value}"${flags}]`); break; } case 'ClassSelector': - if ( this.reValidIdentifier.test(data.name) === false ) { return; } + if ( this.reInvalidIdentifier.test(data.name) ) { return; } out.push(`.${data.name}`); break; case 'Combinator': out.push(data.name === ' ' ? ' ' : ` ${data.name} `); break; case 'Identifier': - if ( this.reValidIdentifier.test(data.name) === false ) { return; } + if ( this.reInvalidIdentifier.test(data.name) ) { return; } out.push(data.name); break; case 'IdSelector': - if ( this.reValidIdentifier.test(data.name) === false ) { return; } + if ( this.reInvalidIdentifier.test(data.name) ) { return; } out.push(`#${data.name}`); break; case 'Nth': { @@ -1639,7 +1639,7 @@ Parser.prototype.SelectorCompiler = class { out.push(data.value); break; case 'TypeSelector': - if ( this.reValidIdentifier.test(data.name) === false ) { return; } + if ( this.reInvalidIdentifier.test(data.name) ) { return; } out.push(data.name); break; default: