Skip to content

Commit c43bfa0

Browse files
Merge branch '3.4' into 4.0
* 3.4: (32 commits) [Form] fix tests and deps [Cache] Rely on mock for Doctrine ArrayCache [FrameworkBundle] Respect debug mode when warm up annotations [Console] Fix docblock of DescriptorInterface::describe [Config] Handle nullable node name + fix inheritdocs [Security] added userChecker to SimpleAuthenticationProvider [Debug] fix test Fix typo in test method name Fixes #26563 (open_basedir restriction in effect) [Debug] Reset previous exception handler ealier to prevent infinite loop add hint in Github pull request template [Validator] Fix docblock of ClassMetadata#members [BrowserKit] Fix cookie path handling when $domain is null [DoctrineBridge] Don't rely on ClassMetadataInfo->hasField in DoctrineOrmTypeGuesser anymore [BrowserKit] Improves CookieJar::get [BrowserKit] Fix Cookie's PHPDoc [DomCrawler] Change bad wording in ChoiceFormField::untick [DomCrawler] Fix the PHPDoc of ChoiceFormField::setValue [DomCrawler] Avoid a useless call to strtolower [FrameworkBundle] HttpCache is not longer abstract ...
2 parents 4b3b60a + 840bb6f commit c43bfa0

File tree

3 files changed

+25
-34
lines changed

3 files changed

+25
-34
lines changed

Cookie.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ class Cookie
4444
/**
4545
* Sets a cookie.
4646
*
47-
* @param string $name The cookie name
48-
* @param string $value The value of the cookie
49-
* @param string $expires The time the cookie expires
50-
* @param string $path The path on the server in which the cookie will be available on
51-
* @param string $domain The domain that the cookie is available
52-
* @param bool $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
53-
* @param bool $httponly The cookie httponly flag
54-
* @param bool $encodedValue Whether the value is encoded or not
47+
* @param string $name The cookie name
48+
* @param string $value The value of the cookie
49+
* @param string|null $expires The time the cookie expires
50+
* @param string|null $path The path on the server in which the cookie will be available on
51+
* @param string $domain The domain that the cookie is available
52+
* @param bool $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
53+
* @param bool $httponly The cookie httponly flag
54+
* @param bool $encodedValue Whether the value is encoded or not
5555
*/
5656
public function __construct(string $name, ?string $value, string $expires = null, string $path = null, string $domain = '', bool $secure = false, bool $httponly = true, bool $encodedValue = false)
5757
{
@@ -112,8 +112,8 @@ public function __toString()
112112
/**
113113
* Creates a Cookie instance from a Set-Cookie header value.
114114
*
115-
* @param string $cookie A Set-Cookie header value
116-
* @param string $url The base URL
115+
* @param string $cookie A Set-Cookie header value
116+
* @param string|null $url The base URL
117117
*
118118
* @return static
119119
*
@@ -242,7 +242,7 @@ public function getRawValue()
242242
/**
243243
* Gets the expires time of the cookie.
244244
*
245-
* @return string The cookie expires time
245+
* @return string|null The cookie expires time
246246
*/
247247
public function getExpiresTime()
248248
{

CookieJar.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,21 @@ public function get($name, $path = '/', $domain = null)
4343
{
4444
$this->flushExpiredCookies();
4545

46-
if (!empty($domain)) {
47-
foreach ($this->cookieJar as $cookieDomain => $pathCookies) {
48-
if ($cookieDomain) {
49-
$cookieDomain = '.'.ltrim($cookieDomain, '.');
50-
if ($cookieDomain != substr('.'.$domain, -strlen($cookieDomain))) {
51-
continue;
52-
}
53-
}
54-
55-
foreach ($pathCookies as $cookiePath => $namedCookies) {
56-
if ($cookiePath != substr($path, 0, strlen($cookiePath))) {
57-
continue;
58-
}
59-
if (isset($namedCookies[$name])) {
60-
return $namedCookies[$name];
61-
}
46+
foreach ($this->cookieJar as $cookieDomain => $pathCookies) {
47+
if ($cookieDomain && $domain) {
48+
$cookieDomain = '.'.ltrim($cookieDomain, '.');
49+
if ($cookieDomain !== substr('.'.$domain, -\strlen($cookieDomain))) {
50+
continue;
6251
}
6352
}
6453

65-
return;
66-
}
67-
68-
// avoid relying on this behavior that is mainly here for BC reasons
69-
foreach ($this->cookieJar as $cookies) {
70-
if (isset($cookies[$path][$name])) {
71-
return $cookies[$path][$name];
54+
foreach ($pathCookies as $cookiePath => $namedCookies) {
55+
if (0 !== strpos($path, $cookiePath)) {
56+
continue;
57+
}
58+
if (isset($namedCookies[$name])) {
59+
return $namedCookies[$name];
60+
}
7261
}
7362
}
7463
}

Tests/CookieJarTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ public function testCookieGetWithSubdirectory()
237237
$this->assertEquals($cookie1, $cookieJar->get('foo', '/test', 'example.com'));
238238
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/', 'example.com'));
239239
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/bar', 'example.com'));
240+
241+
$this->assertEquals($cookie2, $cookieJar->get('foo1', '/bar'));
240242
}
241243

242244
public function testCookieWithWildcardDomain()

0 commit comments

Comments
 (0)