bug #26569 [BrowserKit] Fix cookie path handling when $domain is null (dunglas)
This PR was merged into the 2.7 branch.
Discussion
----------
[BrowserKit] Fix cookie path handling when $domain is null
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? |no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? |no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
The bug is highlighted by the new test: there is an inconsistency in the path handling regarding if a domain is set or not. If it is set, and the cookie is set to a subpath of the passed path, the cookie is returned. However if no domain is set, it is not. This PR fixes this bug.
Commits
-------
acc20fc
[BrowserKit] Fix cookie path handling when $domain is null
This commit is contained in:
commit
bd49884804
@ -43,9 +43,8 @@ class CookieJar
|
|||||||
{
|
{
|
||||||
$this->flushExpiredCookies();
|
$this->flushExpiredCookies();
|
||||||
|
|
||||||
if (!empty($domain)) {
|
|
||||||
foreach ($this->cookieJar as $cookieDomain => $pathCookies) {
|
foreach ($this->cookieJar as $cookieDomain => $pathCookies) {
|
||||||
if ($cookieDomain) {
|
if ($cookieDomain && $domain) {
|
||||||
$cookieDomain = '.'.ltrim($cookieDomain, '.');
|
$cookieDomain = '.'.ltrim($cookieDomain, '.');
|
||||||
if ($cookieDomain !== substr('.'.$domain, -\strlen($cookieDomain))) {
|
if ($cookieDomain !== substr('.'.$domain, -\strlen($cookieDomain))) {
|
||||||
continue;
|
continue;
|
||||||
@ -61,16 +60,6 @@ class CookieJar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// avoid relying on this behavior that is mainly here for BC reasons
|
|
||||||
foreach ($this->cookieJar as $cookies) {
|
|
||||||
if (isset($cookies[$path][$name])) {
|
|
||||||
return $cookies[$path][$name];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -237,6 +237,8 @@ class CookieJarTest extends TestCase
|
|||||||
$this->assertEquals($cookie1, $cookieJar->get('foo', '/test', 'example.com'));
|
$this->assertEquals($cookie1, $cookieJar->get('foo', '/test', 'example.com'));
|
||||||
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/', 'example.com'));
|
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/', 'example.com'));
|
||||||
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/bar', 'example.com'));
|
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/bar', 'example.com'));
|
||||||
|
|
||||||
|
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCookieWithWildcardDomain()
|
public function testCookieWithWildcardDomain()
|
||||||
|
Reference in New Issue
Block a user