skip setting cookies that can't be created successfully
Brian Phillips [Mon, 28 Feb 2011 19:24:35 +0000 (13:24 -0600)]
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

lib/Catalyst/Engine.pm
t/aggregate/live_engine_response_cookies.t
t/lib/TestApp/Controller/Engine/Response/Cookies.pm

index ebbd138..a442f6b 100644 (file)
@@ -93,6 +93,7 @@ sub finalize_cookies {
                 -httponly => $val->{httponly} || 0,
             )
         );
+        next if(!defined $cookie); # warn?
 
         push @cookies, $cookie->as_string;
     }
index 5f2f226..add2cdd 100644 (file)
@@ -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' );
+}
index 320c2e1..884b326 100644 (file)
@@ -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;