Skip to content

Commit

Permalink
fixed small attribute selector bug in Mojo::DOM::CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 15, 2011
1 parent 6225983 commit 40bd59f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@ This file documents the revision history for Perl extension Mojolicious.
1.99 2011-09-15 00:00:00
- Improved documentation.
- Fixed small redirect_to bug. (judofyr, sri)
- Fixed small attribute selector bug in Mojo::DOM::CSS.

1.98 2011-09-14 00:00:00
- Removed Mojo::Server::FastCGI so it can be maintained as a separate
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/DOM/CSS.pm
Expand Up @@ -287,7 +287,7 @@ sub _equation {

sub _regex {
my ($self, $op, $value) = @_;
return unless $value;
return unless defined $value;
$value = quotemeta $self->_unescape($value);

# "~=" (word)
Expand Down Expand Up @@ -340,8 +340,8 @@ sub _selector {
my $found = 0;
for my $name (keys %$attrs) {
if ($name =~ /\:?$key$/) {
++$found and last
if !$regex || ($attrs->{$name} || '') =~ /$regex/;
next unless defined(my $value = $attrs->{$name});
++$found and last if !$regex || $value =~ $regex;
}
}
next if $found;
Expand Down
31 changes: 30 additions & 1 deletion t/mojo/dom.t
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 675;
use Test::More tests => 698;

# "Homer gave me a kidney: it wasn't his, I didn't need it,
# and it came postage due- but I appreciated the gesture!"
Expand Down Expand Up @@ -1963,3 +1963,32 @@ is $dom->find('entry')->[1]->addresses->formatted->text(0),
'right text';
is $dom->find('entry')->[2], undef, 'no result';
is $dom->find('entry')->size, 2, 'right number of elements';

# Find "0" attribute value
$dom = Mojo::DOM->new(<<EOF);
<a accesskey="0">Zero</a>
<a accesskey="1">One</a>
EOF
is $dom->find('a[accesskey]')->[0]->text, 'Zero', 'right text';
is $dom->find('a[accesskey]')->[1]->text, 'One', 'right text';
is $dom->find('a[accesskey]')->[2], undef, 'no result';
is $dom->find('a[accesskey="0"]')->[0]->text, 'Zero', 'right text';
is $dom->find('a[accesskey="0"]')->[1], undef, 'no result';
is $dom->find('a[accesskey^="0"]')->[0]->text, 'Zero', 'right text';
is $dom->find('a[accesskey^="0"]')->[1], undef, 'no result';
is $dom->find('a[accesskey$="0"]')->[0]->text, 'Zero', 'right text';
is $dom->find('a[accesskey$="0]')->[1], undef, 'no result';
is $dom->find('a[accesskey~="0"]')->[0]->text, 'Zero', 'right text';
is $dom->find('a[accesskey~="0]')->[1], undef, 'no result';
is $dom->find('a[accesskey*="0"]')->[0]->text, 'Zero', 'right text';
is $dom->find('a[accesskey*="0]')->[1], undef, 'no result';
is $dom->find('a[accesskey="1"]')->[0]->text, 'One', 'right text';
is $dom->find('a[accesskey="1"]')->[1], undef, 'no result';
is $dom->find('a[accesskey^="1"]')->[0]->text, 'One', 'right text';
is $dom->find('a[accesskey^="1"]')->[1], undef, 'no result';
is $dom->find('a[accesskey$="1"]')->[0]->text, 'One', 'right text';
is $dom->find('a[accesskey$="1]')->[1], undef, 'no result';
is $dom->find('a[accesskey~="1"]')->[0]->text, 'One', 'right text';
is $dom->find('a[accesskey~="1]')->[1], undef, 'no result';
is $dom->find('a[accesskey*="1"]')->[0]->text, 'One', 'right text';
is $dom->find('a[accesskey*="1]')->[1], undef, 'no result';

0 comments on commit 40bd59f

Please sign in to comment.