From: Brian Phillips Date: Mon, 28 Feb 2011 19:24:35 +0000 (-0600) Subject: skip setting cookies that can't be created successfully X-Git-Tag: 5.80033~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=db9407301b748638a6f3b72d459bf7cc74162468 skip setting cookies that can't be created successfully CGI::Simple::Cookie will return undef if either the -name or -value values are undefined. We need to check and see if $cookie is defined before calling ->as_string --- diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index ebbd138..a442f6b 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -93,6 +93,7 @@ sub finalize_cookies { -httponly => $val->{httponly} || 0, ) ); + next if(!defined $cookie); # warn? push @cookies, $cookie->as_string; } diff --git a/t/aggregate/live_engine_response_cookies.t b/t/aggregate/live_engine_response_cookies.t index 5f2f226..add2cdd 100644 --- a/t/aggregate/live_engine_response_cookies.t +++ b/t/aggregate/live_engine_response_cookies.t @@ -71,3 +71,24 @@ my $expected = { this_is_the_real_name => [ qw(this_is_the_real_name foo&bar path /) ], # not "object" }, 'Response Cookies' ); } + +{ + my $response; + ok( $response = request('http://localhost/engine/response/cookies/four'), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ) or diag explain $response; + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + is( $response->header('X-Catalyst-Action'), + 'engine/response/cookies/four', 'Test Action' ); + + my $cookies = {}; + + for my $string ( $response->header('Set-Cookie') ) { + my $cookie = [ split_header_words $string]; + $cookies->{ $cookie->[0]->[0] } = $cookie->[0]; + } + + is_deeply( $cookies, { + good => [qw|good good_cookie path /|], + }, 'Response Cookies' ); +} diff --git a/t/lib/TestApp/Controller/Engine/Response/Cookies.pm b/t/lib/TestApp/Controller/Engine/Response/Cookies.pm index 320c2e1..884b326 100644 --- a/t/lib/TestApp/Controller/Engine/Response/Cookies.pm +++ b/t/lib/TestApp/Controller/Engine/Response/Cookies.pm @@ -32,4 +32,11 @@ sub three : Local { $c->forward('TestApp::View::Dump::Request'); } +sub four : Local { + my ( $self, $c ) = @_; + $c->res->cookies->{good} = { value => 'good_cookie', path => '/' }; + $c->res->cookies->{bad} = { value => undef }; + $c->forward('TestApp::View::Dump::Request'); +} + 1;