From 33773a276529725bb3b66a1b4114be2436d3aeab Mon Sep 17 00:00:00 2001 From: Jean Ragouin Date: Tue, 13 Mar 2018 18:00:05 +0800 Subject: [PATCH 1/4] Update Client.php --- Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client.php b/Client.php index 63d4be77..e9e0d196 100644 --- a/Client.php +++ b/Client.php @@ -78,7 +78,7 @@ public function isFollowingRedirects() } /** - * Sets the maximum number of requests that crawler can follow. + * Sets the maximum number of redirects that crawler can follow. * * @param int $maxRedirects */ @@ -89,7 +89,7 @@ public function setMaxRedirects($maxRedirects) } /** - * Returns the maximum number of requests that crawler can follow. + * Returns the maximum number of redirects that crawler can follow. * * @return int */ From 60d5cbdd9f9818864b290f346364d4bf5ed4bc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 16 Mar 2018 16:11:23 +0100 Subject: [PATCH 2/4] [BrowserKit] Fix Cookie's PHPDoc --- Cookie.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Cookie.php b/Cookie.php index e6159da7..1afd8da5 100644 --- a/Cookie.php +++ b/Cookie.php @@ -44,14 +44,14 @@ class Cookie /** * Sets a cookie. * - * @param string $name The cookie name - * @param string $value The value of the cookie - * @param string $expires The time the cookie expires - * @param string $path The path on the server in which the cookie will be available on - * @param string $domain The domain that the cookie is available - * @param bool $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client - * @param bool $httponly The cookie httponly flag - * @param bool $encodedValue Whether the value is encoded or not + * @param string $name The cookie name + * @param string $value The value of the cookie + * @param string|null $expires The time the cookie expires + * @param string|null $path The path on the server in which the cookie will be available on + * @param string $domain The domain that the cookie is available + * @param bool $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client + * @param bool $httponly The cookie httponly flag + * @param bool $encodedValue Whether the value is encoded or not */ public function __construct($name, $value, $expires = null, $path = null, $domain = '', $secure = false, $httponly = true, $encodedValue = false) { @@ -112,8 +112,8 @@ public function __toString() /** * Creates a Cookie instance from a Set-Cookie header value. * - * @param string $cookie A Set-Cookie header value - * @param string $url The base URL + * @param string $cookie A Set-Cookie header value + * @param string|null $url The base URL * * @return static * @@ -242,7 +242,7 @@ public function getRawValue() /** * Gets the expires time of the cookie. * - * @return string The cookie expires time + * @return string|null The cookie expires time */ public function getExpiresTime() { From 1cc92d410f51226514f617d346c4c6e43b2f7eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 16 Mar 2018 17:11:50 +0100 Subject: [PATCH 3/4] [BrowserKit] Improves CookieJar::get --- CookieJar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CookieJar.php b/CookieJar.php index 232cefc8..faa8f6ec 100644 --- a/CookieJar.php +++ b/CookieJar.php @@ -47,13 +47,13 @@ public function get($name, $path = '/', $domain = null) foreach ($this->cookieJar as $cookieDomain => $pathCookies) { if ($cookieDomain) { $cookieDomain = '.'.ltrim($cookieDomain, '.'); - if ($cookieDomain != substr('.'.$domain, -strlen($cookieDomain))) { + if ($cookieDomain !== substr('.'.$domain, -\strlen($cookieDomain))) { continue; } } foreach ($pathCookies as $cookiePath => $namedCookies) { - if ($cookiePath != substr($path, 0, strlen($cookiePath))) { + if (0 !== strpos($path, $cookiePath)) { continue; } if (isset($namedCookies[$name])) { From b49a059de813b0abda4223c48e766cae2c44bc7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 16 Mar 2018 18:29:18 +0100 Subject: [PATCH 4/4] [BrowserKit] Fix cookie path handling when $domain is null --- CookieJar.php | 35 ++++++++++++----------------------- Tests/CookieJarTest.php | 2 ++ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/CookieJar.php b/CookieJar.php index faa8f6ec..7a4d64c1 100644 --- a/CookieJar.php +++ b/CookieJar.php @@ -43,32 +43,21 @@ public function get($name, $path = '/', $domain = null) { $this->flushExpiredCookies(); - if (!empty($domain)) { - foreach ($this->cookieJar as $cookieDomain => $pathCookies) { - if ($cookieDomain) { - $cookieDomain = '.'.ltrim($cookieDomain, '.'); - if ($cookieDomain !== substr('.'.$domain, -\strlen($cookieDomain))) { - continue; - } - } - - foreach ($pathCookies as $cookiePath => $namedCookies) { - if (0 !== strpos($path, $cookiePath)) { - continue; - } - if (isset($namedCookies[$name])) { - return $namedCookies[$name]; - } + foreach ($this->cookieJar as $cookieDomain => $pathCookies) { + if ($cookieDomain && $domain) { + $cookieDomain = '.'.ltrim($cookieDomain, '.'); + if ($cookieDomain !== substr('.'.$domain, -\strlen($cookieDomain))) { + continue; } } - 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]; + foreach ($pathCookies as $cookiePath => $namedCookies) { + if (0 !== strpos($path, $cookiePath)) { + continue; + } + if (isset($namedCookies[$name])) { + return $namedCookies[$name]; + } } } } diff --git a/Tests/CookieJarTest.php b/Tests/CookieJarTest.php index 9c9e122e..3117e5ce 100644 --- a/Tests/CookieJarTest.php +++ b/Tests/CookieJarTest.php @@ -237,6 +237,8 @@ public function testCookieGetWithSubdirectory() $this->assertEquals($cookie1, $cookieJar->get('foo', '/test', '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')); } public function testCookieWithWildcardDomain()