Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed XML semantics bug in Mojo::DOM::HTML
  • Loading branch information
kraih committed Jan 19, 2014
1 parent 194c5f6 commit c3415ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -15,6 +15,7 @@
inheritance.
- Improved list of available commands to be alphabetical. (jberger)
- Fixed select_field helper to be nondestructive.
- Fixed XML semantics bug in Mojo::DOM::HTML.

4.67 2014-01-11
- Added history and max_history_size attributes to Mojo::Log.
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/DOM/HTML.pm
Expand Up @@ -126,11 +126,11 @@ sub parse {
_end($start, $xml, \$current)
if (!$xml && $VOID{$start}) || $attr =~ m!/\s*$!;

# Relaxed "script" or "style"
next unless $start eq 'script' || $start eq 'style';
# Relaxed "script" or "style" HTML elements
next unless !$xml && ($start eq 'script' || $start eq 'style');
next unless $html =~ m!\G(.*?)<\s*/\s*$start\s*>!gcsi;
push @$current, ['raw', $1];
_end($start, $xml, \$current);
_end($start, 0, \$current);
}
}

Expand Down
21 changes: 12 additions & 9 deletions t/mojo/dom.t
Expand Up @@ -1789,17 +1789,20 @@ is $dom->at('div:root')->text, 'Test', 'right text';
ok !!Mojo::DOM->new->xml(1)->parse('<foo />')->xml, 'XML mode active';
$dom = Mojo::DOM->new->parse(<<'EOF');
<?xml version='1.0' encoding='UTF-8'?>
<table>
<td>
<tr><thead>foo<thead></tr>
</td>
<td>
<tr><thead>bar<thead></tr>
</td>
</table>
<script>
<table>
<td>
<tr><thead>foo<thead></tr>
</td>
<td>
<tr><thead>bar<thead></tr>
</td>
</table>
</script>
EOF
is $dom->find('table > td > tr > thead')->[0]->text, 'foo', 'right text';
is $dom->find('table > td > tr > thead')->[1]->text, 'bar', 'right text';
is $dom->find('script > table > td > tr > thead')->[1]->text, 'bar',
'right text';
is $dom->find('table > td > tr > thead')->[2], undef, 'no result';
is $dom->find('table > td > tr > thead')->size, 2, 'right number of elements';

Expand Down

0 comments on commit c3415ea

Please sign in to comment.