common: fix cookie expire in recent installs
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 8 Mar 2015 06:17:20 +0000 (07:17 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 9 Jun 2015 03:43:43 +0000 (05:43 +0200)
Fatal error trying to stringify undef returned for omitted value
since CGI::Cookie v1.30 (CGI v3.51).

common.inc.plp

index 563c0e48ba5bdfa8986592c91fb46f65d7287732..f6cd6a6f7a93452a66346a7fdef08af0f5a7da43 100644 (file)
@@ -23,15 +23,15 @@ $header{content_type} = 'text/html; charset=utf-8';
 sub stylesheet {
        my %styles = map {$_ => $_} @_;
 
 sub stylesheet {
        my %styles = map {$_ => $_} @_;
 
-       if (exists $get{style}) {
-               $style = $styles{ $get{style} };
+       if (defined( my $setstyle = $get{style} )) {
+               $style = $styles{ $setstyle };
                eval {
                        require CGI::Cookie;
                        my $cookie = CGI::Cookie->new(
                                -name    => 'style',
                eval {
                        require CGI::Cookie;
                        my $cookie = CGI::Cookie->new(
                                -name    => 'style',
-                               -value   => $style,
+                               -value   => $setstyle || '',
                                -path    => '/',  # site-wide; current page is confusing to most users
                                -path    => '/',  # site-wide; current page is confusing to most users
-                               -expires => $style ? '+5y' : '-1d',
+                               -expires => $setstyle ? '+5y' : '-1d',
                        ) or die "empty object returned\n";
                        AddCookie($cookie->as_string);
                } or warn "Unable to create style cookie: $@";
                        ) or die "empty object returned\n";
                        AddCookie($cookie->as_string);
                } or warn "Unable to create style cookie: $@";