Skip to content

Commit 34e89bc

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: [HttpFoundation] Fix PHP 8.1 deprecation in isNotModified
2 parents dd68a3b + 60e8e42 commit 34e89bc

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Response.php

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

1091-
if ($ifNoneMatchEtags = $request->getETags()) {
1092-
$etag = $this->getEtag();
1091+
if (($ifNoneMatchEtags = $request->getETags()) && (null !== $etag = $this->getEtag())) {
10931092
if (0 == strncmp($etag, 'W/', 2)) {
10941093
$etag = substr($etag, 2);
10951094
}

Tests/ResponseTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,20 @@ public function testIsNotModifiedIfModifiedSinceAndEtagWithoutLastModified()
287287
$this->assertFalse($response->isNotModified($request));
288288
}
289289

290+
public function testIfNoneMatchWithoutETag()
291+
{
292+
$request = new Request();
293+
$request->headers->set('If-None-Match', 'randomly_generated_etag');
294+
295+
$this->assertFalse((new Response())->isNotModified($request));
296+
297+
// Test wildcard
298+
$request = new Request();
299+
$request->headers->set('If-None-Match', '*');
300+
301+
$this->assertFalse((new Response())->isNotModified($request));
302+
}
303+
290304
public function testIsValidateable()
291305
{
292306
$response = new Response('', 200, ['Last-Modified' => $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822)]);

0 commit comments

Comments
 (0)