Skip to content

Commit

Permalink
fixed bug in Mojo::DOM::CSS where the :empty pseudo class would not i…
Browse files Browse the repository at this point in the history
…gnore comments and processing instructions
  • Loading branch information
kraih committed Nov 25, 2014
1 parent 190153f commit 1d89d3c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

5.66 2014-11-25
- Fixed bug in Mojo::DOM::CSS where the :empty pseudo class would not ignore
comments and processing instructions.

5.65 2014-11-24
- Improved installable scripts to use #!perl. (jberger)
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojo/DOM/CSS.pm
Expand Up @@ -125,6 +125,8 @@ sub _compile {
return $pattern;
}

sub _empty { $_[0][0] eq 'comment' || $_[0][0] eq 'pi' }

sub _equation {
my $equation = shift;

Expand Down Expand Up @@ -161,7 +163,7 @@ sub _pc {
my ($class, $args, $current) = @_;

# ":empty"
return !defined $current->[4] if $class eq 'empty';
return !grep { !_empty($_) } @$current[4 .. $#$current] if $class eq 'empty';

# ":root"
return $current->[3] && $current->[3][0] eq 'root' if $class eq 'root';
Expand Down
6 changes: 5 additions & 1 deletion t/mojo/dom.t
Expand Up @@ -826,6 +826,8 @@ $dom = Mojo::DOM->new->parse(<<EOF);
</select>
<input type="submit" value="Ok!" />
<input type="checkbox" checked name="I">
<p id="content">test 123</p>
<p id="no_content"><? test ?><!-- 123 --></p>
</form>
EOF
is $dom->find(':root')->[0]->type, 'form', 'right type';
Expand Down Expand Up @@ -854,7 +856,9 @@ is $dom->at('optgroup > *:checked[value="e"]')->text, 'E', 'right text';
is $dom->find(':checked[value="e"]')->[1], undef, 'no result';
is $dom->find(':empty')->[0]->attr->{name}, 'user', 'right name';
is $dom->find('input:empty')->[0]->attr->{name}, 'user', 'right name';
is $dom->at(':empty[type^="ch"]')->attr->{name}, 'groovy', 'right name';
is $dom->at(':empty[type^="ch"]')->attr->{name}, 'groovy', 'right name';
is $dom->at('p')->attr->{id}, 'content', 'right attribute';
is $dom->at('p:empty')->attr->{id}, 'no_content', 'right attribute';

# More pseudo classes
$dom = Mojo::DOM->new->parse(<<EOF);
Expand Down

0 comments on commit 1d89d3c

Please sign in to comment.