From 3f8e3fe0c618ea5b84b516c07cca579b3a366dc3 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 7 Oct 2022 09:12:45 -0400 Subject: [PATCH] Fix nth-of-type() not accepting identifier-based arguments Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/issues/2284#issuecomment-1271552479 --- src/js/static-filtering-parser.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index c4bc49095..0283acd11 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1613,18 +1613,22 @@ Parser.prototype.SelectorCompiler = class { 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 ) { + if ( data.nth.type === 'AnPlusB' ) { + 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}`); - } else { - out.push(`+${b}`); } - } else if ( b !== null ) { - out.push(`${b}`); + } else if ( data.nth.type === 'Identifier' ) { + out.push(data.nth.name); } break; }