Encode cookies per RFC 3986

This commit is contained in:
Zach Borboa
2014-06-28 17:39:16 -07:00
parent a03a603308
commit 2d883cef47
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -204,7 +204,7 @@ class Curl
public function setCookie($key, $value)
{
$this->cookies[$key] = $value;
$this->setOpt(CURLOPT_COOKIE, http_build_query($this->cookies, '', '; '));
$this->setOpt(CURLOPT_COOKIE, http_build_query($this->cookies, '', '; ', PHP_QUERY_RFC3986));
}
public function setCookieFile($cookie_file)
+12
View File
@@ -331,6 +331,18 @@ class CurlTest extends PHPUnit_Framework_TestCase
)) === 'yum');
}
public function testCookieEncoding()
{
$curl = new Curl();
$curl->setCookie('cookie', 'Om nom nom nom');
$reflectionClass = new ReflectionClass('\Curl\Curl');
$reflectionProperty = $reflectionClass->getProperty('options');
$reflectionProperty->setAccessible(true);
$options = $reflectionProperty->getValue($curl);
$this->assertEquals('cookie=Om%20nom%20nom%20nom', $options[CURLOPT_COOKIE]);
}
public function testCookieFile()
{
$cookie_file = dirname(__FILE__) . '/cookies.txt';