Skip to content

Commit 6214b87

Browse files
committed
Add test for Curl::getResponseCookies()
1 parent 561bf6e commit 6214b87

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Curl/Curl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ public function head($url, $data = array())
445445
*/
446446
public function headerCallback($ch, $header)
447447
{
448-
if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) == 1) {
449-
$this->responseCookies[$cookie[1]] = $cookie[2];
448+
if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) === 1) {
449+
$this->responseCookies[$cookie[1]] = trim($cookie[2], " \n\r\t\0\x0B");
450450
}
451451
$this->rawResponseHeaders .= $header;
452452
return strlen($header);

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,10 @@ public function testMultipleCookieResponse()
753753
$test = new Test();
754754
$test->server('multiple_cookie', 'GET');
755755
$this->assertEquals('cookie1=scrumptious,cookie2=mouthwatering', $test->curl->responseHeaders['Set-Cookie']);
756+
757+
$response_cookies = $test->curl->getResponseCookies();
758+
$this->assertEquals('scrumptious', $response_cookies['cookie1']);
759+
$this->assertEquals('mouthwatering', $response_cookies['cookie2']);
756760
}
757761

758762
public function testDefaultTimeout()

0 commit comments

Comments
 (0)