Permalink
Browse files

fixed JSON rendering bug

  • Loading branch information...
kraih committed Mar 4, 2014
1 parent 3ea1eb3 commit 80357a533fc5d50a63c980859cf853f5ca54af8a
Showing with 10 additions and 2 deletions.
  1. +2 −1 lib/Mojolicious/Renderer.pm
  2. +8 −1 t/mojolicious/lite_app.t
@@ -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';
}
View
@@ -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') };
@@ -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)')

0 comments on commit 80357a5

Please sign in to comment.