From 743210f5df0efbd6a3f75d19ba945db17b5a6faf Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 24 Sep 2022 17:27:20 -0400 Subject: [PATCH] Fix incomplete parsing of nth-of-type() and some other pseudo-classes Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2284 Regression from: - https://github.com/gorhill/uBlock/commit/a71b71e4c8a2037fc68970bc8912a76732edaade --- src/js/static-filtering-parser.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 610cf15a4..6a43af719 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1515,6 +1515,10 @@ Parser.prototype.SelectorCompiler = class { args = out; out.push({ data }); break; + case 'Nth': { + out.push({ data }); + break; + } case 'PseudoClassSelector': case 'PseudoElementSelector': if ( head ) { args = []; } @@ -1594,9 +1598,28 @@ Parser.prototype.SelectorCompiler = class { case 'Combinator': out.push(data.name === ' ' ? ' ' : ` ${data.name} `); break; + case 'Identifier': + out.push(data.name); + break; case 'IdSelector': out.push(`#${data.name}`); break; + case 'Nth': { + const a = parseInt(data.nth.a, 10) || null; + const b = parseInt(data.nth.b, 10) || null; + if ( a !== null ) { + out.push(`${a}n`); + if ( b === null ) { break; } + if ( b < 0 ) { + out.push(`${b}`); + } else { + out.push(`+${b}`); + } + } else if ( b !== null ) { + out.push(`${b}`); + } + break; + } case 'ActionSelector': case 'PseudoClassSelector': case 'PseudoElementSelector':