Skip to content

Commit

Permalink
fixed small trim bug in Mojo::DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 23, 2012
1 parent 7d21f95 commit be0ef1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/Mojo/DOM.pm
Expand Up @@ -267,7 +267,7 @@ sub text {
sub text_after {
my ($self, $trim) = @_;

# Find text elements after
# Find following text elements
return '' if (my $tree = $self->tree)->[0] eq 'root';
my (@elements, $started);
for my $e (@{_elements($tree->[3])}) {
Expand All @@ -277,13 +277,13 @@ sub text_after {
push @elements, $e;
}

return _text(\@elements, 0, _trim($tree, $trim));
return _text(\@elements, 0, _trim($tree->[3], $trim));
}

sub text_before {
my ($self, $trim) = @_;

# Find text elements before
# Find preceding text elements
return '' if (my $tree = $self->tree)->[0] eq 'root';
my @elements;
for my $e (@{_elements($tree->[3])}) {
Expand All @@ -292,7 +292,7 @@ sub text_before {
@elements = () if $e->[0] eq 'tag';
}

return _text(\@elements, 0, _trim($tree, $trim));
return _text(\@elements, 0, _trim($tree->[3], $trim));
}

sub to_xml { shift->[0]->render }
Expand Down
4 changes: 3 additions & 1 deletion t/mojo/dom.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 718;
use Test::More tests => 720;

use ojo;
use Mojo::Util 'encode';
Expand Down Expand Up @@ -1882,6 +1882,8 @@ is $dom->div->pre->code->text, "like\n it\n really", 'right text';
is $dom->div->pre->code->text(0), "like\n it\n really", 'right text';
is $dom->div->pre->code->all_text, "like\n it\n really", 'right text';
is $dom->div->pre->code->all_text(0), "like\n it\n really", 'right text';
is $dom->div->pre->text_before, 'looks', 'right text';
is $dom->div->pre->text_after, 'works', 'right text';

# Text siblings
$dom = Mojo::DOM->new(<<EOF);
Expand Down

0 comments on commit be0ef1d

Please sign in to comment.