From 64976eb40160161c2e769e8045f5bb7c1b205345 Mon Sep 17 00:00:00 2001 From: Curtis Farnham Date: Wed, 31 Jan 2018 11:44:37 -0800 Subject: [PATCH] Fix for #1894 - "Undefined offset: 0" --- src/Cookie/SetCookie.php | 4 ++-- tests/Cookie/SetCookieTest.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Cookie/SetCookie.php b/src/Cookie/SetCookie.php index 7a427df9c..ddb819b22 100644 --- a/src/Cookie/SetCookie.php +++ b/src/Cookie/SetCookie.php @@ -35,8 +35,8 @@ public static function fromString($cookie) $data = self::$defaults; // Explode the cookie string using a series of semicolons $pieces = array_filter(array_map('trim', explode(';', $cookie))); - // The name of the cookie (first kvp) must include an equal sign. - if (empty($pieces) || !strpos($pieces[0], '=')) { + // The name of the cookie (first kvp) must exist and include an equal sign. + if (empty($pieces[0]) || !strpos($pieces[0], '=')) { return new self($data); } diff --git a/tests/Cookie/SetCookieTest.php b/tests/Cookie/SetCookieTest.php index 4f27e610d..71ff3943e 100644 --- a/tests/Cookie/SetCookieTest.php +++ b/tests/Cookie/SetCookieTest.php @@ -223,6 +223,7 @@ public function cookieParserDataProvider() ), array('', []), array('foo', []), + array('; foo', []), array( 'foo="bar"', [