8000 [HttpFoundation] Fix PHP 8.1 deprecation in isNotModified · symfony/symfony@e436f1d · GitHub
[go: up one dir, main page]

Skip to content

Commit e436f1d

Browse files
committed
[HttpFoundation] Fix PHP 8.1 deprecation in isNotModified
1 parent 495eba3 commit e436f1d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,7 @@ public function isNotModified(Request $request): bool
10791079
$lastModified = $this->headers->get('Last-Modified');
10801080
$modifiedSince = $request->headers->get('If-Modified-Since');
10811081

1082-
if ($ifNoneMatchEtags = $request->getETags()) {
1083-
$etag = $this->getEtag();
1082+
if (($ifNoneMatchEtags = $request->getETags()) && (null !== $etag = $this->getEtag())) {
10841083
if (0 == strncmp($etag, 'W/', 2)) {
10851084
$etag = substr($etag, 2);
10861085
}

src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ public function testIsNotModifiedIfModifiedSinceAndEtagWithoutLastModified()
284284
$this->assertFalse($response->isNotModified($request));
285285
}
286286

287+
public function testIfNoneMatchWithoutETag()
288+
{
289+
$request = new Request();
290+
$request->headers->set('If-None-Match', 'randomly_generated_etag');
291+
292+
$this->assertFalse((new Response())->isNotModified($request));
293+
}
294+
287295
public function testIsValidateable()
288296
{
289297
$response = new Response('', 200, ['Last-Modified' => $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822)]);

0 commit comments

Comments
 (0)
0