Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed bug in Mojo::DOM::HTML where non-self-closing elements were not…
… handled correctly
  • Loading branch information
kraih committed Mar 11, 2014
1 parent 3e3e997 commit 50abf7d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,5 +1,7 @@

4.89 2014-03-10
4.89 2014-03-11
- Fixed bug in Mojo::DOM::HTML where non-self-closing elements were not
handled correctly.

4.88 2014-03-09
- Added build_controller method to Mojolicious.
Expand Down
16 changes: 14 additions & 2 deletions lib/Mojo/DOM/HTML.pm
Expand Up @@ -85,6 +85,17 @@ my @PHRASING = (
my @OBSOLETE = qw(acronym applet basefont big font strike tt);
my %PHRASING = map { $_ => 1 } @OBSOLETE, @PHRASING;

# HTML elements that don't get their self-closing flag acknowledged
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)
);

sub parse {
my ($self, $html) = @_;

Expand Down Expand Up @@ -121,9 +132,10 @@ sub parse {

_start($start, \%attrs, $xml, \$current);

# Element without end tag
# Element without end tag (self-closing)
_end($start, $xml, \$current)
if (!$xml && $EMPTY{$start}) || $attr =~ m!/\s*$!;
if !$xml && $EMPTY{$start}
or ($xml || !$BLOCK{$start}) && $attr =~ m!/\s*$!;

# Relaxed "script" or "style" HTML elements
next if $xml || ($start ne 'script' && $start ne 'style');
Expand Down
5 changes: 5 additions & 0 deletions t/mojo/dom.t
Expand Up @@ -2320,6 +2320,11 @@ is $dom->parse('<!--0-->'), '<!--0-->', 'successful roundtrip';
is $dom->parse('<![CDATA[0]]>'), '<![CDATA[0]]>', 'successful roundtrip';
is $dom->parse('<?0?>'), '<?0?>', 'successful roundtrip';

# Not self-closing
$dom = Mojo::DOM->new('<div /><div><pre />test</div>');
is $dom->at('div > div > pre')->text, 'test', 'right text';
is "$dom", '<div><div><pre>test</pre></div></div>', 'right result';

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

0 comments on commit 50abf7d

Please sign in to comment.