This repository was archived by the owner on Jan 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ public static function fromString($headerLine, $bypassHeaderFieldName = false)
139
139
$ header ->setVersion ((int ) $ headerValue );
140
140
break ;
141
141
case 'maxage ' :
142
- $ header ->setMaxAge (( int ) $ headerValue );
142
+ $ header ->setMaxAge ($ headerValue );
143
143
break ;
144
144
default :
145
145
// Intentionally omitted
@@ -342,14 +342,19 @@ public function getVersion()
342
342
* Set Max-Age
343
343
*
344
344
* @param int $maxAge
345
- * @throws Exception\InvalidArgumentException
346
345
* @return SetCookie
347
346
*/
348
347
public function setMaxAge ($ maxAge )
349
348
{
350
- if ($ maxAge !== null && (! is_int ($ maxAge) || ( $ maxAge < 0 ) )) {
351
- throw new Exception \ InvalidArgumentException ( ' Invalid Max-Age number specified ' ) ;
349
+ if ($ maxAge === null || ! is_numeric ($ maxAge )) {
350
+ return $ this ;
352
351
}
352
+
353
+ $ maxAge = (int ) $ maxAge ;
354
+ if ($ maxAge < 0 ) {
355
+ $ maxAge = 0 ;
356
+ }
357
+
353
358
$ this ->maxAge = $ maxAge ;
354
359
return $ this ;
355
360
}
Original file line number Diff line number Diff line change @@ -661,6 +661,33 @@ public static function validCookieWithInfoProvider()
661
661
],
662
662
'emptykey=; Domain=docs.foo.com ' ,
663
663
],
664
+ [
665
+ 'Set-Cookie: emptykey; Domain=docs.foo.com; Max-Age=foo; ' ,
666
+ [
667
+ 'name ' => 'myname ' ,
668
+ 'value ' => '' ,
669
+ 'domain ' => 'docs.foo.com ' ,
670
+ ],
671
+ 'emptykey=; Domain=docs.foo.com '
672
+ ],
673
+ [
674
+ 'Set-Cookie: emptykey; Domain=docs.foo.com; Max-Age=-1480312904; ' ,
675
+ [
676
+ 'name ' => 'myname ' ,
677
+ 'value ' => '' ,
678
+ 'domain ' => 'docs.foo.com ' ,
679
+ ],
680
+ 'emptykey=; Max-Age=0; Domain=docs.foo.com '
681
+ ],
682
+ [
683
+ 'Set-Cookie: emptykey; Domain=docs.foo.com; Max-Age=100; ' ,
684
+ [
685
+ 'name ' => 'myname ' ,
686
+ 'value ' => '' ,
687
+ 'domain ' => 'docs.foo.com ' ,
688
+ ],
689
+ 'emptykey=; Max-Age=100; Domain=docs.foo.com '
690
+ ],
664
691
];
665
692
}
666
693
}
You can’t perform that action at this time.
0 commit comments