This commit is contained in:
Javier Casares 2026-07-18 13:29:38 +00:00
commit 916d7845be

View file

@ -2,7 +2,7 @@
namespace GuzzleHttp\Cookie;
use GuzzleHttp\Utils;
use GuzzleHttp\Exception\InvalidArgumentException;
/**
* Persists non-session cookies using a JSON formatted file
@ -64,7 +64,12 @@ class FileCookieJar extends CookieJar
}
}
$jsonStr = Utils::jsonEncode($json);
$jsonStr = \json_encode($json);
if (\JSON_ERROR_NONE !== \json_last_error()) {
throw new InvalidArgumentException('json_encode error: '.\json_last_error_msg());
}
/** @var non-empty-string $jsonStr */
if (false === \file_put_contents($filename, $jsonStr, \LOCK_EX)) {
throw new \RuntimeException("Unable to save file {$filename}");
}
@ -89,7 +94,11 @@ class FileCookieJar extends CookieJar
return;
}
$data = Utils::jsonDecode($json, true);
$data = \json_decode($json, true);
if (\JSON_ERROR_NONE !== \json_last_error()) {
throw new InvalidArgumentException('json_decode error: '.\json_last_error_msg());
}
if (\is_array($data)) {
foreach ($data as $cookie) {
$this->setCookie(new SetCookie($cookie));