Skip to content

Commit

Permalink
Merge pull request #317 from stof/fix_cookie
Browse files Browse the repository at this point in the history
Fix the encoding of cookies on PHP 7.4
  • Loading branch information
stof committed Mar 11, 2020
2 parents 727f987 + 1cb8b45 commit 8e81282
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,19 @@ public function setCookie($name, $value = null)
return;
}

// 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) {
$encodedValue = rawurlencode($value);
} else {
$encodedValue = urlencode($value);
}

$cookieArray = array(
'name' => $name,
'value' => urlencode($value),
'value' => $encodedValue,
'secure' => false, // thanks, chibimagic!
);

Expand All @@ -456,6 +466,14 @@ 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']);
}

return urldecode($cookie['value']);
}
}
Expand Down

0 comments on commit 8e81282

Please sign in to comment.