Skip to content

Commit 443aa73

Browse files
committed
Cookie: preserve encode space to '%20' in delimiter, when multiple cookies available
1 parent db63250 commit 443aa73

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Curl/Curl.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,10 @@ public function setDigestAuthentication($username, $password = '')
543543
*/
544544
public function setCookie($key, $value)
545545
{
546-
$this->cookies[$key] = $value;
547-
$this->setOpt(CURLOPT_COOKIE, str_replace(' ', '%20', urldecode(http_build_query($this->cookies, '', '; '))));
546+
$this->cookies[$key] = $value;
547+
$this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function($name) {
548+
return $name . '=' . str_replace(' ', '%20', $this->cookies[$name]);
549+
}, array_keys($this->cookies))));
548550
}
549551

550552
/**

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,19 @@ public function testCookieEncodingSpace()
661661
$options = $reflectionProperty->getValue($curl);
662662
$this->assertEquals('cookie=Om%20nom%20nom%20nom', $options[CURLOPT_COOKIE]);
663663
}
664+
665+
public function testMultipleCookies()
666+
{
667+
$curl = new Curl();
668+
$curl->setCookie('cookie', 'Om nom nom nom');
669+
$curl->setCookie('foo', 'bar');
670+
671+
$reflectionClass = new ReflectionClass('\Curl\Curl');
672+
$reflectionProperty = $reflectionClass->getProperty('options');
673+
$reflectionProperty->setAccessible(true);
674+
$options = $reflectionProperty->getValue($curl);
675+
$this->assertEquals('cookie=Om%20nom%20nom%20nom; foo=bar', $options[CURLOPT_COOKIE]);
676+
}
664677

665678
public function testCookieEncodingColon()
666679
{

0 commit comments

Comments
 (0)