mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 12:14:36 +00:00
Cookie: preserve encode space to '%20' in delimiter, when multiple cookies available
This commit is contained in:
+4
-2
@@ -543,8 +543,10 @@ class Curl
|
||||
*/
|
||||
public function setCookie($key, $value)
|
||||
{
|
||||
$this->cookies[$key] = $value;
|
||||
$this->setOpt(CURLOPT_COOKIE, str_replace(' ', '%20', urldecode(http_build_query($this->cookies, '', '; '))));
|
||||
$this->cookies[$key] = $value;
|
||||
$this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function($name) {
|
||||
return $name . '=' . str_replace(' ', '%20', $this->cookies[$name]);
|
||||
}, array_keys($this->cookies))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -661,6 +661,19 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$options = $reflectionProperty->getValue($curl);
|
||||
$this->assertEquals('cookie=Om%20nom%20nom%20nom', $options[CURLOPT_COOKIE]);
|
||||
}
|
||||
|
||||
public function testMultipleCookies()
|
||||
{
|
||||
$curl = new Curl();
|
||||
$curl->setCookie('cookie', 'Om nom nom nom');
|
||||
$curl->setCookie('foo', 'bar');
|
||||
|
||||
$reflectionClass = new ReflectionClass('\Curl\Curl');
|
||||
$reflectionProperty = $reflectionClass->getProperty('options');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
$options = $reflectionProperty->getValue($curl);
|
||||
$this->assertEquals('cookie=Om%20nom%20nom%20nom; foo=bar', $options[CURLOPT_COOKIE]);
|
||||
}
|
||||
|
||||
public function testCookieEncodingColon()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user