Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Header/SetCookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ public function isSessionCookie()
487487

488488
public function isValidForRequest($requestDomain, $path, $isSecure = false)
489489
{
490-
if ($this->getDomain() && (strrpos($requestDomain, $this->getDomain()) !== false)) {
490+
if ($this->getDomain() && (strrpos($requestDomain, $this->getDomain()) === false)) {
491491
return false;
492492
}
493493

test/Header/SetCookieTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,19 @@ public function testSetCookieCanAppendOtherHeadersInWhenCreatingString()
153153
$this->assertEquals($target, $headerLine);
154154
}
155155

156-
/** Implmentation specific tests here */
156+
public function testIsValidForRequestSubdomainMatch()
157+
{
158+
$setCookieHeader = new SetCookie(
159+
'myname', 'myvalue', 'Wed, 13-Jan-2021 22:23:01 GMT',
160+
'/accounts', '.foo.com', true, true, 99, 9
161+
);
162+
$this->assertTrue($setCookieHeader->isValidForRequest('bar.foo.com', '/accounts', true));
163+
$this->assertFalse($setCookieHeader->isValidForRequest('bar.foooo.com', '/accounts', true)); // false because of domain
164+
$this->assertFalse($setCookieHeader->isValidForRequest('bar.foo.com', '/accounts', false)); // false because of isSecure
165+
$this->assertFalse($setCookieHeader->isValidForRequest('bar.foo.com', '/somethingelse', true)); // false because of path
166+
}
167+
168+
/** Implementation specific tests here */
157169

158170
/**
159171
* @group ZF2-169

0 commit comments

Comments
 (0)