Skip to content

Commit 2d883ce

Browse files
committed
Encode cookies per RFC 3986
1 parent a03a603 commit 2d883ce

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Curl/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function setReferrer($referrer)
204204
public function setCookie($key, $value)
205205
{
206206
$this->cookies[$key] = $value;
207-
$this->setOpt(CURLOPT_COOKIE, http_build_query($this->cookies, '', '; '));
207+
$this->setOpt(CURLOPT_COOKIE, http_build_query($this->cookies, '', '; ', PHP_QUERY_RFC3986));
208208
}
209209

210210
public function setCookieFile($cookie_file)

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,18 @@ public function testCookies()
331331
)) === 'yum');
332332
}
333333

334+
public function testCookieEncoding()
335+
{
336+
$curl = new Curl();
337+
$curl->setCookie('cookie', 'Om nom nom nom');
338+
339+
$reflectionClass = new ReflectionClass('\Curl\Curl');
340+
$reflectionProperty = $reflectionClass->getProperty('options');
341+
$reflectionProperty->setAccessible(true);
342+
$options = $reflectionProperty->getValue($curl);
343+
$this->assertEquals('cookie=Om%20nom%20nom%20nom', $options[CURLOPT_COOKIE]);
344+
}
345+
334346
public function testCookieFile()
335347
{
336348
$cookie_file = dirname(__FILE__) . '/cookies.txt';

0 commit comments

Comments
 (0)