Browse Source

Return timestamps as strings.

This prevents overflow issues on 32bit windows systems for far futures
expiration dates.
Mark Story 9 years ago
parent
commit
ca2f2286d3
2 changed files with 7 additions and 3 deletions
  1. 6 3
      src/Http/Cookie/Cookie.php
  2. 1 0
      tests/TestCase/Http/Cookie/CookieTest.php

+ 6 - 3
src/Http/Cookie/Cookie.php

@@ -177,15 +177,18 @@ class Cookie implements CookieInterface
     /**
      * Get the timestamp from the expiration time
      *
-     * @return int
+     * Timestamps are strings as large timestamps can overflow MAX_INT
+     * in 32bit systems.
+     *
+     * @return string|null The expiry time as a string timestamp.
      */
     public function getExpiresTimestamp()
     {
         if (!$this->expiresAt) {
-            return 0;
+            return null;
         }
 
-        return (int)$this->expiresAt->format('U');
+        return $this->expiresAt->format('U');
     }
 
     /**

+ 1 - 0
tests/TestCase/Http/Cookie/CookieTest.php

@@ -372,6 +372,7 @@ class CookieTest extends TestCase
 
         $this->assertContains('expires=Wed, 15-Jun-2022', $new->toHeaderValue());
         $this->assertContains('GMT', $new->toHeaderValue());
+        $this->assertSame($date->format('U'), $new->getExpiresTimestamp());
     }
 
     /**