Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with malformed domain that contains a "/" character #1999

Merged
merged 2 commits into from Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Cookie/SetCookie.php
Expand Up @@ -35,8 +35,8 @@ public static function fromString($cookie)
$data = self::$defaults;
// Explode the cookie string using a series of semicolons
$pieces = array_filter(array_map('trim', explode(';', $cookie)));
// The name of the cookie (first kvp) must include an equal sign.
if (empty($pieces) || !strpos($pieces[0], '=')) {
// The name of the cookie (first kvp) must exist and include an equal sign.
if (empty($pieces[0]) || !strpos($pieces[0], '=')) {
return new self($data);
}

Expand Down Expand Up @@ -348,7 +348,7 @@ public function matchesDomain($domain)
return false;
}

return (bool) preg_match('/\.' . preg_quote($cookieDomain) . '$/', $domain);
return (bool) preg_match('/\.' . preg_quote($cookieDomain, '/') . '$/', $domain);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/Cookie/SetCookieTest.php
Expand Up @@ -115,6 +115,9 @@ public function testMatchesDomain()

$cookie->setDomain('.local');
$this->assertTrue($cookie->matchesDomain('example.local'));

$cookie->setDomain('example.com/'); // malformed domain
$this->assertFalse($cookie->matchesDomain('example.com'));
}

public function pathMatchProvider()
Expand Down Expand Up @@ -223,6 +226,7 @@ public function cookieParserDataProvider()
),
array('', []),
array('foo', []),
array('; foo', []),
array(
'foo="bar"',
[
Expand Down