8000 bug #48112 [HttpFoundation] Compare cookie with null value as empty s… · symfony/symfony@1ee474f · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ee474f

Browse files
bug #48112 [HttpFoundation] Compare cookie with null value as empty string in ResponseCookieValueSame (fancyweb)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Compare cookie with null value as empty string in ResponseCookieValueSame | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #48105 | License | MIT | Doc PR | - We already consider `null` as `''` when we "compute" the cookie: https://github.com/symfony/symfony/blob/4d4c411a609ef62dcbdfd6f309deab76a7431135/src/Symfony/Component/HttpFoundation/Cookie.php#L253 So in the related issue, `self::assertResponseCookieValueSame('SOME_COOKIE_NAME', '');` could be used. WDYT `@werwolf666`? Commits ------- 0cc7368 [HttpFoundation] Compare cookie with null value as empty string in ResponseCookieValueSame
2 parents 5548611 + 0cc7368 commit 1ee474f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseCookieValueSame.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function matches($response): bool
5959
return false;
6060
}
6161

62-
return $this->value === $cookie->getValue();
62+
return $this->value === (string) $cookie->getValue();
6363
}
6464

6565
/**

src/Symfony/Component/HttpFoundation/Tests/Test/Constraint/ResponseCookieValueSameTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ public function testConstraint()
4141

4242
$this->fail();
4343
}
44+
45+
public function testCookieWithNullValueIsComparedAsEmptyString()
46+
{
47+
$response = new Response();
48+
$response->headers->setCookie(Cookie::create('foo', null, 0, '/path'));
49+
50+
$this->assertTrue((new ResponseCookieValueSame('foo', '', '/path'))->evaluate($response, '', true));
51+
}
4452
}

0 commit comments

Comments
 (0)
0