Skip to content

Commit

Permalink
bugix: CookieJar returns cookies with domain "domain.com" for domain …
Browse files Browse the repository at this point in the history
…"foodomain.com"
  • Loading branch information
povilas authored and fabpot committed Sep 25, 2013
1 parent 9016f7d commit 8980954
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/BrowserKit/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ public function allValues($uri, $returnsRawValue = false)
$cookies = array();
foreach ($this->cookieJar as $domain => $pathCookies) {
if ($domain) {
$domain = ltrim($domain, '.');
if ($domain != substr($parts['host'], -strlen($domain))) {
$domain = '.'.ltrim($domain, '.');
if ($domain != substr('.'.$parts['host'], -strlen($domain))) {
continue;
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,13 @@ public function testCookieWithSameNameButDifferentDomains()
$this->assertEquals(array('foo' => 'bar1'), $cookieJar->allValues('http://foo.example.com/'));
$this->assertEquals(array('foo' => 'bar2'), $cookieJar->allValues('http://bar.example.com/'));
}

public function testCookieWithWildcardDomain()
{
$cookieJar = new CookieJar();
$cookieJar->set(new Cookie('foo', 'bar', null, '/', '.example.com'));

$this->assertEquals(array('foo' => 'bar'), $cookieJar->allValues('http://www.example.com'));
$this->assertEmpty($cookieJar->allValues('http://wwwexample.com'));
}
}

0 comments on commit 8980954

Please sign in to comment.