Skip to content

Commit

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

4.65 2014-01-02
- Deprecated use of hash references for optgroup generation with
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/DOM.pm
Expand Up @@ -136,7 +136,7 @@ sub remove { shift->replace('') }
sub replace {
my ($self, $new) = @_;
my $tree = $self->tree;
return $self->xml(undef)->parse($new) if $tree->[0] eq 'root';
return $self->parse($new) if $tree->[0] eq 'root';
return $self->_replace($tree, $self->_parse("$new"));
}

Expand Down
15 changes: 7 additions & 8 deletions t/mojo/dom.t
Expand Up @@ -1746,14 +1746,13 @@ is $element->type, 'Element', 'right child';
is $element->parent->type, 'XMLTest', 'right parent';
ok $element->root->xml, 'XML mode active';
$dom->replace('<XMLTest2 />');
ok !$dom->xml, 'XML mode not detected';
is $dom->children->[0], '<xmltest2></xmltest2>', 'right result';
$dom->replace(<<EOF);
<?xml version='1.0' encoding='UTF-8'?>
<XMLTest3 />
EOF
ok $dom->xml, 'XML mode detected';
is $dom->children->[0], '<XMLTest3 />', 'right result';
ok $dom->xml, 'XML mode active';
is $dom, '<XMLTest2 />', 'right result';

# Ensure HTML semantics
$dom = Mojo::DOM->new->xml(0)
->parse('<?xml version="1.0" encoding="UTF-8"?><br><div>Test</div>');
is $dom->at('div:root')->text, 'Test', 'right text';

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

0 comments on commit 6177489

Please sign in to comment.