Skip to content

Commit

Permalink
fixed small charset handling bug in Mojo::DOM::HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 17, 2013
1 parent 4eb1364 commit 3befa92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/DOM/HTML.pm
Expand Up @@ -77,8 +77,8 @@ sub parse {
my ($self, $html) = @_;

if (my $charset = $self->charset) {
if (my $chars = decode $charset, $html) { $html = $chars }
else { $self->charset(undef) }
if (defined(my $chars = decode $charset, $html)) { $html = $chars }
else { $self->charset(undef) }
}

my $tree = ['root'];
Expand Down
8 changes: 8 additions & 0 deletions t/mojo/dom.t
Expand Up @@ -2154,6 +2154,14 @@ is $dom->charset, undef, 'no charset';
is $dom->at('#invalid')->text, "\x89", 'right text';
is "$dom", qq{<div id="invalid">\x89</div>}, 'right result';

# "0" with charset
$dom = Mojo::DOM->new->charset('UTF-8');
$dom->parse('0');
is $dom->charset, 'UTF-8', 'right charset';
is "$dom", '0', 'right result';
$dom->append_content('');
is "$dom", encode('UTF-8', '0☃'), 'right result';

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

0 comments on commit 3befa92

Please sign in to comment.