Subject: | Setting "expires" to 0 to clear cookie results in the cookie being set to expire "now" |
When attempting to clear a cookie by setting the expiry time to the
epoch, CGI::Util interprets 0 as being an offset rather than an absolute
value. This behaviour seems counter-intuitive since all other integers
are interpreted absolutely.
I've attached a patch for code and tests.
Subject: | CGI-3.25.patch |
Index: CGI/Util.pm
===================================================================
--- CGI/Util.pm (.../branches/cpan) (revision 524)
+++ CGI/Util.pm (.../trunk) (revision 527)
@@ -257,7 +257,7 @@
# If you don't supply one of these forms, we assume you are
# specifying the date yourself
my($offset);
- if (!$time || (lc($time) eq 'now')) {
+ if (!defined($time) || !length($time) || (lc($time) eq 'now')) {
$offset = 0;
} elsif ($time=~/^\d+/) {
return $time;
Index: t/cookie.t
===================================================================
--- t/cookie.t (.../branches/cpan) (revision 524)
+++ t/cookie.t (.../trunk) (revision 527)
@@ -7,7 +7,7 @@
# ensure the blib's are in @INC, else we might use the core CGI.pm
use lib qw(blib/lib blib/arch);
-use Test::More tests => 96;
+use Test::More tests => 97;
use CGI::Util qw(escape unescape);
use POSIX qw(strftime);
@@ -166,6 +166,13 @@
is($c->path, '/', 'path atribute is set to default');
ok(!defined $c->secure , 'secure attribute is set');
+ $c = CGI::Cookie->new(
+ -name => 'quux',
+ -value => 'quuux',
+ -expires => 0,
+ );
+ like($c->expires, qr(^Thu, 01-Jan-1970), "Setting expiry to the epoch is allowed");
+
# I'm really not happy about the restults of this section. You pass
# the new method invalid arguments and it just merilly creates a
# broken object :-)