M src/http/Cookie.php => src/http/Cookie.php +1 -1
@@ 10,6 10,7 @@ final class Cookie
public static function fromString(string $cookieString): self
{
+ $cookieString = ltrim($cookieString, '; ');
$parts = explode(';', $cookieString);
$nameAndValue = explode('=', $parts[0]);
@@ 25,7 26,6 @@ final class Cookie
public function send(): void
{
$options = [
-
];
setcookie($this->name, $this->value, $options);
}
A tests/http.php => tests/http.php +10 -0
@@ 0,0 1,10 @@
+<?php
+declare(strict_types=1);
+
+namespace Thirdplace;
+
+$sut = Cookie::fromString('foo=bar');
+assertEquals(['foo', 'bar'], [$sut->name, $sut->value]);
+
+$sut = Cookie::fromString('; foo=bar');
+assertEquals(['foo', 'bar'], [$sut->name, $sut->value]);<
\ No newline at end of file