Skip to content

Commit

Permalink
add json value support for setCookie header
Browse files Browse the repository at this point in the history
with unittest
  • Loading branch information
ClemensSahs committed Sep 4, 2013
1 parent 2a33a10 commit b4b9063
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
10 changes: 3 additions & 7 deletions library/Zend/Http/Header/SetCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,9 @@ public function getFieldValue()
return '';
}

$value = $this->getValue();
if (strpos($value, '"')!==false) {
$value = '"'.urlencode(str_replace('"', '', $value)).'"';
} else {
$value = urlencode($value);
}
$fieldValue = $this->getName() . '=' . $value;
$value = urlencode($this->getValue());

$fieldValue = $this->getName() . '="' . $value .'"';

$version = $this->getVersion();
if ($version!==null) {
Expand Down
20 changes: 20 additions & 0 deletions tests/ZendTest/Http/Header/SetCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,26 @@ public function testToString($cStr, $info, $expected)
$this->assertEquals($cookie->getFieldName() . ': ' . $expected, $cookie->toString());
}

public function testSetJsonValue()
{
$cookieName ="fooCookie";
$jsonData = json_encode(array('foo'=>'bar'));

$cookie= new SetCookie($cookieName,$jsonData);

$regExp = sprintf('#^%s="%s"#',$cookieName,urlencode($jsonData));
$this->assertRegExp($regExp,$cookie->getFieldValue());

$cookieName ="fooCookie";
$jsonData = json_encode(array('foo'=>'bar'));

$cookie= new SetCookie($cookieName,$jsonData);
$cookie->setDomain('example.org');

$regExp = sprintf('#^%s="%s"; Domain=#',$cookieName,urlencode($jsonData));
$this->assertRegExp($regExp,$cookie->getFieldValue());
}

/**
* Provide valid cookie strings with information about them
*
Expand Down

0 comments on commit b4b9063

Please sign in to comment.