Cookie: preserve encode space to '%20' in delimiter, when multiple cookies available

This commit is contained in:
Maxim Epishchev
2015-10-27 11:19:18 +03:00
parent db632505f5
commit 443aa73851
2 changed files with 17 additions and 2 deletions
+4 -2
View File
@@ -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))));
}
/**
+13
View File
@@ -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()
{