From e61e47adb1333d1720d26119b48ceefac222e9f7 Mon Sep 17 00:00:00 2001 From: Brian Gottreu Date: Sat, 23 Aug 2014 22:46:16 -0500 Subject: [PATCH] Save a cookie when the expiration is unset The behavior of HTTP::Cookies::Netscape is different than HTTP::Cookies' when saving and loading cookies that lack an explicit expiration. --- lib/HTTP/Cookies/Netscape.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/HTTP/Cookies/Netscape.pm b/lib/HTTP/Cookies/Netscape.pm index 5972029e..c885074c 100644 --- a/lib/HTTP/Cookies/Netscape.pm +++ b/lib/HTTP/Cookies/Netscape.pm @@ -28,9 +28,11 @@ sub load next if /^\s*$/; tr/\n\r//d; my($domain,$bool1,$path,$secure, $expires,$key,$val) = split(/\t/, $_); + my $maxage; + $maxage = $expires-$now if $expires; $secure = ($secure eq "TRUE"); $self->set_cookie(undef,$key,$val,$path,$domain,undef, - 0,$secure,$expires-$now, 0); + 0,$secure,$maxage, 0); } close(FILE); 1; @@ -57,8 +59,13 @@ EOT my($version,$key,$val,$path,$domain,$port, $path_spec,$secure,$expires,$discard,$rest) = @_; return if $discard && !$self->{ignore_discard}; - $expires = $expires ? $expires - $HTTP::Cookies::EPOCH_OFFSET : 0; - return if $now > $expires; + if($expires) { + $expires = $expires - $HTTP::Cookies::EPOCH_OFFSET; + return if $now > $expires; + } + else { + $expires = 0; + } $secure = $secure ? "TRUE" : "FALSE"; my $bool = $domain =~ /^\./ ? "TRUE" : "FALSE"; print FILE join("\t", $domain, $bool, $path, $secure, $expires, $key, $val), "\n";