From 8d8d74ec413a1223d835c182c0acae0851dbc672 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sun, 2 Nov 2014 19:19:05 +0100 Subject: [PATCH] Drop nth-child support of all negative sequences This removes parsing support for selectors such as :nth-child(-n-6). According to the CSS spec this isn't valid anyway (confirmed by testing it in Chromium). As a result there's no point in supporting it in any way. --- lib/oga/css/parser.y | 6 +----- .../oga/css/parser/pseudo_classes/nth_child_spec.rb | 13 ------------- .../parser/pseudo_classes/nth_last_child_spec.rb | 6 ------ 3 files changed, 1 insertion(+), 24 deletions(-) diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index 738787e..7b03892 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -413,12 +413,8 @@ end compare = :lte end - # -n-6, -n-4, etc - if !step and non_positive_number?(offset) - node = s(:eq, count_call, s(:int, -1)) - # 2n+2, 2n-4, etc - elsif offset + if offset # -2n if step and non_positive_number?(step) mod_val = s(:int, -step.children[0]) diff --git a/spec/oga/css/parser/pseudo_classes/nth_child_spec.rb b/spec/oga/css/parser/pseudo_classes/nth_child_spec.rb index e13ce3c..c62345b 100644 --- a/spec/oga/css/parser/pseudo_classes/nth_child_spec.rb +++ b/spec/oga/css/parser/pseudo_classes/nth_child_spec.rb @@ -52,12 +52,6 @@ describe Oga::CSS::Parser do ) end - example 'parse the x:nth-child(-n-6) pseudo class' do - parse_css('x:nth-child(-n-6)').should == parse_xpath( - 'descendant-or-self::x[count(preceding-sibling::*) = -1]' - ) - end - example 'parse the x:nth-child(2n) pseudo class' do parse_css('x:nth-child(2n)').should == parse_css('x:nth-child(even)') end @@ -83,13 +77,6 @@ describe Oga::CSS::Parser do ) end - example 'parse the x:nth-child(-2n-6) pseudo class' do - parse_css('x:nth-child(-2n-6)').should == parse_xpath( - 'descendant-or-self::x[((count(preceding-sibling::*) + 1) <= -2) ' \ - 'and (((count(preceding-sibling::*) + 1) - -2) mod 2) = 0]' - ) - end - example 'parse the x:nth-child(-2n+6) pseudo class' do parse_css('x:nth-child(-2n+6)').should == parse_xpath( 'descendant-or-self::x[((count(preceding-sibling::*) + 1) <= 6) ' \ diff --git a/spec/oga/css/parser/pseudo_classes/nth_last_child_spec.rb b/spec/oga/css/parser/pseudo_classes/nth_last_child_spec.rb index 359807c..8212191 100644 --- a/spec/oga/css/parser/pseudo_classes/nth_last_child_spec.rb +++ b/spec/oga/css/parser/pseudo_classes/nth_last_child_spec.rb @@ -52,12 +52,6 @@ describe Oga::CSS::Parser do ) end - example 'parse the x:nth-last-child(-n-6) pseudo class' do - parse_css('x:nth-last-child(-n-6)').should == parse_xpath( - 'descendant-or-self::x[count(following-sibling::*) = -1]' - ) - end - example 'parse the x:nth-last-child(2n) pseudo class' do parse_css('x:nth-last-child(2n)').should == parse_css( 'x:nth-last-child(even)'