From f387514aab6f93af49b52fc92e8befb60b09c13e Mon Sep 17 00:00:00 2001 From: Peter Philipp Date: Thu, 28 Apr 2022 08:43:55 +0200 Subject: [PATCH] fix: Check if cookies are iterable before iterating It can happen that the returned value is not iterable. The geetAllCookies() methode also declares the its return as "mixed". --- src/Selenium2Driver.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index abf8333f..09f528ef 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -462,17 +462,19 @@ public function setCookie($name, $value = null) public function getCookie($name) { $cookies = $this->wdSession->getAllCookies(); - foreach ($cookies as $cookie) { - if ($cookie['name'] === $name) { - // PHP 7.4 changed the way it encodes cookies to better respect the spec. - // This assumes that the server and the Mink client run on the same version (or - // at least the same side of the behavior change), so that the server and Mink - // consider the same value. - if (\PHP_VERSION_ID >= 70400) { - return rawurldecode($cookie['value']); + if (is_iterable($cookies)) { + foreach ($cookies as $cookie) { + if ($cookie['name'] === $name) { + // PHP 7.4 changed the way it encodes cookies to better respect the spec. + // This assumes that the server and the Mink client run on the same version (or + // at least the same side of the behavior change), so that the server and Mink + // consider the same value. + if (\PHP_VERSION_ID >= 70400) { + return rawurldecode($cookie['value']); + } + + return urldecode($cookie['value']); } - - return urldecode($cookie['value']); } } }