mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-28 03:00:55 +00:00
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:
+1
-1
@@ -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, '', '; '))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user