diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 3d184d5..902924c 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -544,7 +544,9 @@ 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->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function($k, $v) { + return $k . '=' . str_replace(' ', '%20', $v); + }, array_keys($this->cookies), array_values($this->cookies)))); } /** diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 01d7337..3072b51 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -662,6 +662,19 @@ class CurlTest extends PHPUnit_Framework_TestCase $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() { $curl = new Curl();