From: Gerda Shank Date: Thu, 24 May 2012 16:47:01 +0000 (-0400) Subject: fix body_parameters is undef when no params X-Git-Tag: 5.90013~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=a7d2a53019cca4a6ebd29ccfc31139697f0dfdb8 fix body_parameters is undef when no params --- diff --git a/Changes b/Changes index fdf77c6..ef21fb5 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ # This file documents the revision history for Perl extension Catalyst. + Bug fixes: + - Fix request body parameters is undef with no parameters + 5.90012 - 2012-05-16 09:59:00 Distribution META.yml changes: diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index 6610358..d2c1c7f 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -220,7 +220,7 @@ sub prepare_body_parameters { my ( $self ) = @_; $self->prepare_body if ! $self->_has_body; - return unless $self->_body; + return {} unless $self->_body; return $self->_body->param; } diff --git a/t/lib/TestApp/Controller/BodyParams.pm b/t/lib/TestApp/Controller/BodyParams.pm index 5732211..ea6bf3a 100644 --- a/t/lib/TestApp/Controller/BodyParams.pm +++ b/t/lib/TestApp/Controller/BodyParams.pm @@ -10,4 +10,11 @@ sub default : Private { $c->res->status(200); } +sub no_params : Local { + my ( $self, $c ) = @_; + my $params = $c->req->body_parameters; + $c->res->output(ref $params); + $c->res->status(200); +} + 1; diff --git a/t/live_catalyst_test.t b/t/live_catalyst_test.t index e7f8df9..8248527 100644 --- a/t/live_catalyst_test.t +++ b/t/live_catalyst_test.t @@ -50,5 +50,10 @@ my $req = '/dump/request'; is($response, 'that', 'body param overridden'); } +{ + my $response = request( POST( '/bodyparams/no_params' ) )->content; + is($response, 'HASH', 'empty body param is hashref'); +} + done_testing;