Skip to content

Commit

Permalink
[BrowserKit] fixed cookie management (see RFC 2109)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 24, 2011
1 parent 4f47fc7 commit aa356e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/Symfony/Component/BrowserKit/CookieJar.php
Expand Up @@ -108,12 +108,15 @@ public function allValues($uri)
{
$this->flushExpiredCookies();

$parts = parse_url($uri);
$parts = array_replace(array('path' => '/'), parse_url($uri));

$cookies = array();
foreach ($this->cookieJar as $cookie) {
if ($cookie->getDomain() && $cookie->getDomain() != substr($parts['host'], -strlen($cookie->getDomain()))) {
continue;
if ($cookie->getDomain()) {
$domain = ltrim($cookie->getDomain(), '.');
if ($domain != substr($parts['host'], -strlen($domain))) {
continue;
}
}

if ($cookie->getPath() != substr($parts['path'], 0, strlen($cookie->getPath()))) {
Expand Down
5 changes: 4 additions & 1 deletion tests/Symfony/Tests/Component/BrowserKit/CookieJarTest.php
Expand Up @@ -79,7 +79,8 @@ public function testAllValues($uri, $values)
$cookieJar->set($cookie1 = new Cookie('foo_nothing', 'foo'));
$cookieJar->set($cookie2 = new Cookie('foo_expired', 'foo', time() - 86400));
$cookieJar->set($cookie3 = new Cookie('foo_path', 'foo', null, '/foo'));
$cookieJar->set($cookie4 = new Cookie('foo_domain', 'foo', null, '/', 'example.com'));
$cookieJar->set($cookie4 = new Cookie('foo_domain', 'foo', null, '/', '.example.com'));
$cookieJar->set($cookie4 = new Cookie('foo_strict_domain', 'foo', null, '/', '.www4.example.com'));
$cookieJar->set($cookie5 = new Cookie('foo_secure', 'foo', null, '/', '', true));

$this->assertEquals($values, array_keys($cookieJar->allValues($uri)), '->allValues() returns the cookie for a given URI');
Expand All @@ -88,11 +89,13 @@ public function testAllValues($uri, $values)
public function provideAllValuesValues()
{
return array(
array('http://www.example.com', array('foo_nothing', 'foo_domain')),
array('http://www.example.com/', array('foo_nothing', 'foo_domain')),
array('http://foo.example.com/', array('foo_nothing', 'foo_domain')),
array('http://foo.example1.com/', array('foo_nothing')),
array('https://foo.example.com/', array('foo_nothing', 'foo_domain', 'foo_secure')),
array('http://www.example.com/foo/bar', array('foo_nothing', 'foo_path', 'foo_domain')),
array('http://www4.example.com/', array('foo_nothing', 'foo_domain', 'foo_strict_domain')),
);
}
}

0 comments on commit aa356e7

Please sign in to comment.