Skip to content

Commit

Permalink
fixed more complex :scope ancestor selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Aug 15, 2015
1 parent e8e2245 commit 9cb7b1c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/Mojo/DOM/CSS.pm
Expand Up @@ -29,8 +29,7 @@ sub _ancestor {
while ($current = $current->[3]) {
return undef
if ($current->[0] eq 'root' || $current eq $tree)
&& $selectors->[2][0][0] ne 'pc'
&& $selectors->[2][0][1] ne 'scope';
&& !_scope($selectors->[$pos]);
return 1 if _combinator($selectors, $current, $tree, $pos);
last if $one;
}
Expand Down Expand Up @@ -195,6 +194,8 @@ sub _pc {
return undef;
}

sub _scope { $_[0] && $_[0][0][0] eq 'pc' && $_[0][0][1] eq 'scope' }

sub _select {
my ($one, $tree, $group) = @_;

Expand Down
1 change: 1 addition & 0 deletions t/mojo/dom.t
Expand Up @@ -1235,6 +1235,7 @@ is $dom->at('div')->at(':scope > p')->text, 'One', 'right text';
is $dom->at('div')->at('> p')->text, 'One', 'right text';
is $dom->at('div')->at(':scope a')->text, 'Link', 'right text';
ok !$dom->at('div')->at(':scope > a'), 'not a child';
is $dom->at('div')->at(':scope > p > a')->text, 'Link','right text';
is $dom->find('div')->last->at(':scope p')->text, 'Three', 'right text';
is $dom->find('div')->last->at(':scope > p')->text, 'Three', 'right text';
is $dom->find('div')->last->at('> p')->text, 'Three', 'right text';
Expand Down

0 comments on commit 9cb7b1c

Please sign in to comment.