Skip to content

Commit fc1223f

Browse files
Allow URLs that don't contain a path
1 parent 1ad7d05 commit fc1223f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ public static function fromString($cookie, $url = null)
152152
);
153153

154154
if (null !== $url) {
155-
if ((false === $urlParts = parse_url($url)) || !isset($urlParts['host']) || !isset($urlParts['path'])) {
155+
if ((false === $urlParts = parse_url($url)) || !isset($urlParts['host'])) {
156156
throw new \InvalidArgumentException(sprintf('The URL "%s" is not valid.', $url));
157157
}
158158

159159
$values['domain'] = $urlParts['host'];
160-
$values['path'] = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/'));
160+
$values['path'] = isset($urlParts['path']) ? substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')) : '';
161161
}
162162

163163
foreach ($parts as $part) {

src/Symfony/Component/BrowserKit/Tests/CookieTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public function testFromStringWithCapitalization()
7575
public function testFromStringWithUrl()
7676
{
7777
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar', 'http://www.example.com/'));
78+
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar', 'http://www.example.com'));
79+
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar', 'http://www.example.com?foo'));
7880
$this->assertEquals('foo=bar; domain=www.example.com; path=/foo', (string) Cookie::FromString('foo=bar', 'http://www.example.com/foo/bar'));
7981
$this->assertEquals('foo=bar; domain=www.example.com; path=/', (string) Cookie::FromString('foo=bar; path=/', 'http://www.example.com/foo/bar'));
8082
$this->assertEquals('foo=bar; domain=www.myotherexample.com; path=/', (string) Cookie::FromString('foo=bar; domain=www.myotherexample.com', 'http://www.example.com/'));

0 commit comments

Comments
 (0)