Fix #174: Correctly set cookie value when using http_build_query().

http_build_query() url encodes the cookie data array. Use urldecode() to undo
the URL-encoding and allow characters including the colon (":").
This commit is contained in:
Zach Borboa
2015-04-29 12:38:07 -07:00
parent 0d26131176
commit a79e64b2ca
2 changed files with 14 additions and 2 deletions
+1 -1
View File
@@ -535,7 +535,7 @@ class Curl
public function setCookie($key, $value)
{
$this->cookies[$key] = $value;
$this->setOpt(CURLOPT_COOKIE, str_replace('+', '%20', http_build_query($this->cookies, '', '; ')));
$this->setOpt(CURLOPT_COOKIE, str_replace(' ', '%20', urldecode(http_build_query($this->cookies, '', '; '))));
}
/**
+13 -1
View File
@@ -603,7 +603,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
)));
}
public function testCookieEncoding()
public function testCookieEncodingSpace()
{
$curl = new Curl();
$curl->setCookie('cookie', 'Om nom nom nom');
@@ -615,6 +615,18 @@ class CurlTest extends PHPUnit_Framework_TestCase
$this->assertEquals('cookie=Om%20nom%20nom%20nom', $options[CURLOPT_COOKIE]);
}
public function testCookieEncodingColon()
{
$curl = new Curl();
$curl->setCookie('JSESSIONID', '0000wd-PcsB3bZ-KzYGAqm_rKlm:17925chrl');
$reflectionClass = new ReflectionClass('\Curl\Curl');
$reflectionProperty = $reflectionClass->getProperty('options');
$reflectionProperty->setAccessible(true);
$options = $reflectionProperty->getValue($curl);
$this->assertEquals('JSESSIONID=0000wd-PcsB3bZ-KzYGAqm_rKlm:17925chrl', $options[CURLOPT_COOKIE]);
}
public function testCookieFile()
{
$cookie_file = dirname(__FILE__) . '/cookies.txt';