Skip to content

Commit

Permalink
fixed bug in Mojo::DOM::HTML where <image> was not treated as an alia…
Browse files Browse the repository at this point in the history
…s for <img>
  • Loading branch information
kraih committed Mar 11, 2014
1 parent 6c13b15 commit 01b7c95
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -2,6 +2,8 @@
4.89 2014-03-11
- Fixed bug in Mojo::DOM::HTML where non-self-closing elements were not
handled correctly.
- Fixed bug in Mojo::DOM::HTML where <image> was not treated as an alias for
<img>.

4.88 2014-03-09
- Added build_controller method to Mojolicious.
Expand Down
10 changes: 6 additions & 4 deletions lib/Mojo/DOM/HTML.pm
Expand Up @@ -90,10 +90,10 @@ my %BLOCK = map { $_ => 1 } (
qw(a address applet article aside b big blockquote body button caption),
qw(center code col colgroup dd details dialog dir div dl dt em fieldset),
qw(figcaption figure font footer form frameset h1 h2 h3 h4 h5 h6 head),
qw(header hgroup html i iframe image li listing main marquee menu nav nobr),
qw(noframes noscript object ol optgroup option p plaintext pre rp rt s),
qw(script section select small strike strong style summary table tbody td),
qw(template textarea tfoot th thead title tr tt u ul xmp)
qw(header hgroup html i iframe li listing main marquee menu nav nobr),
qw(noembed noframes noscript object ol optgroup option p plaintext pre rp),
qw(rt s script section select small strike strong style summary table),
qw(tbody td template textarea tfoot th thead title tr tt u ul xmp)
);

sub parse {
Expand Down Expand Up @@ -130,6 +130,8 @@ sub parse {
$attrs{$key} = defined $value ? html_unescape($value) : $value;
}

# "image" is an alias for "img"
$start = 'img' if !$xml && $start eq 'image';
_start($start, \%attrs, $xml, \$current);

# Element without end tag (self-closing)
Expand Down
9 changes: 7 additions & 2 deletions t/mojo/dom.t
Expand Up @@ -223,11 +223,11 @@ is "$dom", '<script><i><b>h:)g</b>a</i><b>fce</b>1<b>d</b></script>',
'right result';

# XML nodes
$dom = Mojo::DOM->new->xml(1)->parse('<b>test</b>');
$dom = Mojo::DOM->new->xml(1)->parse('<b>test<image /></b>');
ok $dom->at('b')->contents->first->xml, 'XML mode active';
ok $dom->at('b')->contents->first->replace('<br>')->contents->first->xml,
'XML mode active';
is "$dom", '<b><br /></b>', 'right result';
is "$dom", '<b><br /><image /></b>', 'right result';

# Treating nodes as elements
$dom = Mojo::DOM->new('foo<b>bar</b>baz');
Expand Down Expand Up @@ -2329,6 +2329,11 @@ is $dom->find('p > svg > circle')->size, 2, 'two circles';
is "$dom", '<p><svg><circle></circle><circle></circle></svg></p>',
'right result';

# "image"
$dom = Mojo::DOM->new('<image src="foo.png">test');
is $dom->at('img')->{src}, 'foo.png', 'right attribute';
is "$dom", '<img src="foo.png">test', 'right result';

# Comments
$dom = Mojo::DOM->new(<<EOF);
<!-- HTML5 -->
Expand Down

0 comments on commit 01b7c95

Please sign in to comment.