Skip to content

Commit

Permalink
fixed escaping bugs in Mojo::DOM::CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 4, 2014
1 parent 93266ac commit 010d1c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -3,6 +3,7 @@
- Added success attribute to Test::Mojo.
- Improved Mojo::DOM::CSS and Mojo::DOM::HTML performance.
- Fixed XML detection bug in Mojo::DOM.
- Fixed escaping bugs in Mojo::DOM::CSS.

4.65 2014-01-02
- Deprecated use of hash references for optgroup generation with
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/DOM/CSS.pm
Expand Up @@ -57,7 +57,7 @@ sub _attr {
# Ignore namespace prefix
my $attrs = $current->[2];
for my $name (keys %$attrs) {
next unless $name =~ /(?:^|:)$key$/;
next unless $name =~ /(?:^|:)\Q$key\E$/;
return 1 unless defined $attrs->{$name} && defined $regex;
return 1 if $attrs->{$name} =~ $regex;
}
Expand Down Expand Up @@ -317,7 +317,7 @@ sub _selector {
# Tag (ignore namespace prefix)
if ($type eq 'tag') {
my $tag = $s->[1];
return undef unless $tag eq '*' || $current->[1] =~ /(?:^|:)$tag$/;
return undef unless $tag eq '*' || $current->[1] =~ /(?:^|:)\Q$tag\E$/;
}

# Attribute
Expand Down
16 changes: 9 additions & 7 deletions t/mojo/dom.t
Expand Up @@ -493,21 +493,23 @@ is $dom->at('number')->ancestors('meta')->first->{xmlns}, 'uri:meta-ns',
ok !!$dom->at('nons')->match('book > nons'), 'element did match';
ok !$dom->at('title')->match('book > nons > section'), 'element did not match';

# Namespace with dot
# Dots
$dom = Mojo::DOM->new(<<EOF);
<?xml version="1.0"?>
<foo xmlns:foo.bar="uri:first">
<bar xmlns:fooxbar="uri:second">
<foo.bar:baz>First</fooxbar:baz>
<fooxbar:yada>Second</foo.bar:yada>
<fooxbar:ya.da>Second</foo.bar:ya.da>
</bar>
</foo>
EOF
is $dom->at('foo bar baz')->text, 'First', 'right text';
is $dom->at('baz')->namespace, 'uri:first', 'right namespace';
is $dom->at('foo bar yada')->text, 'Second', 'right text';
is $dom->at('yada')->namespace, 'uri:second', 'right namespace';
is $dom->at('foo')->namespace, '', 'no namespace';
is $dom->at('foo bar baz')->text, 'First', 'right text';
is $dom->at('baz')->namespace, 'uri:first', 'right namespace';
is $dom->at('foo bar ya\.da')->text, 'Second', 'right text';
is $dom->at('ya\.da')->namespace, 'uri:second', 'right namespace';
is $dom->at('foo')->namespace, '', 'no namespace';
is $dom->at('[xml\.s]'), undef, 'no result';
is $dom->at('b\.z'), undef, 'no result';

# Yadis
$dom = Mojo::DOM->new->parse(<<'EOF');
Expand Down

0 comments on commit 010d1c7

Please sign in to comment.