Skip to content

Commit

Permalink
fixed JSON rendering bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 4, 2014
1 parent 3ea1eb3 commit 80357a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/Mojolicious/Renderer.pm
Expand Up @@ -98,7 +98,8 @@ sub render {
}

# JSON
elsif (my $json = delete $stash->{json}) {
elsif (exists $stash->{json}) {
my $json = delete $stash->{json};
$self->handlers->{json}->($self, $c, \$output, {json => $json});
return $output, 'json';
}
Expand Down
9 changes: 8 additions & 1 deletion t/mojolicious/lite_app.t
Expand Up @@ -316,7 +316,9 @@ post '/malformed_utf8' => sub {
};

get '/json' => sub {
shift->render(json => {foo => [1, -2, 3, 'b☃r']}, layout => 'layout');
my $self = shift;
return $self->render(json => undef) if $self->param('null');
$self->render(json => {foo => [1, -2, 3, 'b☃r']}, layout => 'layout');
};

get '/autostash' => sub { shift->render(handler => 'ep', foo => 'bar') };
Expand Down Expand Up @@ -892,6 +894,11 @@ $t->get_ok('/json')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')
->json_is('/foo/3', 'b☃r', 'right value')->json_has('/foo')
->json_hasnt('/bar');

# JSON ("null")
$t->get_ok('/json?null=1')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->content_type_is('application/json')->json_is(undef);

# Stash values in template
$t->get_ok('/autostash?bar=23')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
Expand Down

0 comments on commit 80357a5

Please sign in to comment.