Skip to content

Commit

Permalink
fixed textarea and title parsing bugs in Mojo::DOM::HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 14, 2014
1 parent 37dc0cc commit 5b4680e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,4 +1,7 @@

4.90 2014-03-14
- Fixed textarea and title parsing bugs in Mojo::DOM::HTML.

4.89 2014-03-13
- Added support for template variants.
- Improved built-in templates with unobtrusive menu bar.
Expand Down
10 changes: 7 additions & 3 deletions lib/Mojo/DOM/HTML.pm
Expand Up @@ -49,6 +49,10 @@ my $TOKEN_RE = qr/
)??
/xis;

# HTML elements that only contain raw text
my %RAW = map { $_ => 1 } qw(script style);
my %RCDATA = map { $_ => 1 } qw(title textarea);

# HTML elements with optional end tags
my %END = (
body => ['head'],
Expand Down Expand Up @@ -138,10 +142,10 @@ sub parse {
_end($start, $xml, \$current)
if !$xml && $EMPTY{$start} || ($xml || !$BLOCK{$start}) && $closing;

# Relaxed "script" or "style" HTML elements
next if $xml || $start ne 'script' && $start ne 'style';
# Raw text elements
next if $xml || !$RAW{$start} && !$RCDATA{$start};
next unless $html =~ m!\G(.*?)<\s*/\s*$start\s*>!gcsi;
_node($current, 'raw', $1);
_node($current, 'raw', $RCDATA{$start} ? html_unescape $1 : $1);
_end($start, 0, \$current);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -43,7 +43,7 @@ has types => sub { Mojolicious::Types->new };
has validator => sub { Mojolicious::Validator->new };

our $CODENAME = 'Top Hat';
our $VERSION = '4.89';
our $VERSION = '4.90';

sub AUTOLOAD {
my $self = shift;
Expand Down
10 changes: 10 additions & 0 deletions t/mojo/dom.t
Expand Up @@ -2334,6 +2334,16 @@ $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';

# "title"
$dom = Mojo::DOM->new('<title> <p>test&lt;</title>');
is $dom->at('title')->text, ' <p>test<', 'right text';
is "$dom", '<title> <p>test<</title>', 'right result';

# "textarea"
$dom = Mojo::DOM->new('<textarea id="a"> <p>test&lt;</textarea>');
is $dom->at('textarea#a')->text, ' <p>test<', 'right text';
is "$dom", '<textarea id="a"> <p>test<</textarea>', 'right result';

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

0 comments on commit 5b4680e

Please sign in to comment.