Skip to content

Commit

Permalink
improve Mojo::DOM::CSS to support selectors with leading and trailing…
Browse files Browse the repository at this point in the history
… whitespace
  • Loading branch information
kraih committed Oct 15, 2015
1 parent c99ece3 commit dca86b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,5 +1,7 @@

6.25 2015-10-14
6.25 2015-10-15
- Improved Mojo::DOM::CSS to support selectors with leading and trailing
whitespace.
- Fixed "0" value bug in Mojo::JSON::Pointer.

6.24 2015-10-13
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojo/DOM/CSS.pm
@@ -1,6 +1,8 @@
package Mojo::DOM::CSS;
use Mojo::Base -base;

use Mojo::Util 'trim';

has 'tree';

my $ESCAPE_RE = qr/\\[^0-9a-fA-F]|\\[0-9a-fA-F]{1,6}/;
Expand Down Expand Up @@ -72,7 +74,7 @@ sub _combinator {
}

sub _compile {
my $css = "$_[0]";
my $css = trim "$_[0]";

my $group = [[]];
while (my $selectors = $group->[-1]) {
Expand Down
5 changes: 5 additions & 0 deletions t/mojo/dom.t
Expand Up @@ -2432,6 +2432,11 @@ is $dom->at('span + b')->text, 'b', 'right text';
is $dom->at('b + span')->text, 'c', 'right text';
is "$dom", '<span>a</span><b>b</b><span>c</span>', 'right result';

# Selectors with leading and trailing whitespace
$dom = Mojo::DOM->new('<div id=foo><b>works</b></div>');
is $dom->at(' div b ')->text, 'works', 'right text';
is $dom->at(' :not( #foo ) ')->text, 'works', 'right text';

# "0"
$dom = Mojo::DOM->new('0');
is "$dom", '0', 'right result';
Expand Down

0 comments on commit dca86b8

Please sign in to comment.