Skip to content
Browse files

Fix & Tests for #782 - Malformed / missing cookies causing warnings

  • Loading branch information...
1 parent c5c684d commit 014ed33288f8be5e20436330af47659779a6492e @LoonyPandora committed Apr 24, 2012
Showing with 19 additions and 2 deletions.
  1. +1 −1 lib/Dancer/Cookies.pm
  2. +18 −1 t/09_cookies/05_api.t
View
2 lib/Dancer/Cookies.pm
@@ -38,7 +38,7 @@ sub parse_cookie_from_env {
# we want `cookie_name' as the value and `foo=bar' as the value
my( $name,$value ) = split(/\s*=\s*/, $cookie, 2);
my @values;
- if ( $value ne '' ) {
+ if ( defined $value && $value ne '' ) {
@values = map { uri_unescape($_) } split( /[&;]/, $value );
}
$cookies->{$name} =
View
19 t/09_cookies/05_api.t
@@ -8,7 +8,7 @@ my @tests = (
{ name => 'msg', value => 'hello; world', opts => { http_only => 0 } },
);
-plan tests => scalar (@tests * 5) + 11;
+plan tests => scalar (@tests * 5) + 12;
is_deeply(cookies, {}, "cookies() return a hashref");
@@ -63,3 +63,20 @@ Dancer::Cookies->init;
$cookies = Dancer::Cookies->cookies;
like $cookies->{fbs_102}->value, qr/access_token\=/;
+
+# Test for undef cookie values from technically invalid cookies issue #782
+eval {
+ use warnings FATAL => qw( all );
+
+ $env = {
+ REQUEST_METHOD => 'GET',
+ SCRIPT_NAME => '/',
+ HTTP_COOKIE => 'invalid_cookie=1,2,3',
+ };
+
+ $request = Dancer::Request->new(env => $env);
+ Dancer::SharedData->request($request);
+ Dancer::Cookies->init;
+};
+unlike($@, qr/Use of uninitialized value in string/, 'undef or invalid cookies are quietly ignored');
+

0 comments on commit 014ed33

Please sign in to comment.
Something went wrong with that request. Please try again.