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 @@ -141,7 +141,7 @@ public static function fromString($headerLine, $bypassHeaderFieldName = false)
141
141
$ header ->setVersion ((int ) $ headerValue );
142
142
break ;
143
143
case 'maxage ' :
144
- $ header ->setMaxAge (( int ) $ headerValue );
144
+ $ header ->setMaxAge ($ headerValue );
145
145
break ;
146
146
default :
147
147
// Intentionally omitted
@@ -344,14 +344,19 @@ public function getVersion()
344
344
* Set Max-Age
345
345
*
346
346
* @param int $maxAge
347
- * @throws Exception\InvalidArgumentException
348
347
* @return SetCookie
349
348
*/
350
349
public function setMaxAge ($ maxAge )
351
350
{
352
- if ($ maxAge !== null && (! is_int ($ maxAge) || ( $ maxAge < 0 ) )) {
353
- throw new Exception \ InvalidArgumentException ( ' Invalid Max-Age number specified ' ) ;
351
+ if ($ maxAge === null || ! is_numeric ($ maxAge )) {
352
+ return $ this ;
354
353
}
354
+
355
+ $ maxAge = (int ) $ maxAge ;
356
+ if ($ maxAge < 0 ) {
357
+ $ maxAge = 0 ;
358
+ }
359
+
355
360
$ this ->maxAge = $ maxAge ;
356
361
return $ this ;
357
362
}
Original file line number Diff line number Diff line change @@ -645,6 +645,33 @@ public static function validCookieWithInfoProvider()
645
645
],
646
646
'emptykey=; Domain=docs.foo.com '
647
647
],
648
+ [
649
+ 'Set-Cookie: emptykey; Domain=docs.foo.com; Max-Age=foo; ' ,
650
+ [
651
+ 'name ' => 'myname ' ,
652
+ 'value ' => '' ,
653
+ 'domain ' => 'docs.foo.com ' ,
654
+ ],
655
+ 'emptykey=; Domain=docs.foo.com '
656
+ ],
657
+ [
658
+ 'Set-Cookie: emptykey; Domain=docs.foo.com; Max-Age=-1480312904; ' ,
659
+ [
660
+ 'name ' => 'myname ' ,
661
+ 'value ' => '' ,
662
+ 'domain ' => 'docs.foo.com ' ,
663
+ ],
664
+ 'emptykey=; Max-Age=0; Domain=docs.foo.com '
665
+ ],
666
+ [
667
+ 'Set-Cookie: emptykey; Domain=docs.foo.com; Max-Age=100; ' ,
668
+ [
669
+ 'name ' => 'myname ' ,
670
+ 'value ' => '' ,
671
+ 'domain ' => 'docs.foo.com ' ,
672
+ ],
673
+ 'emptykey=; Max-Age=100; Domain=docs.foo.com '
674
+ ],
648
675
];
649
676
}
650
677
}
You can’t perform that action at this time.
0 commit comments