Skip to content

Commit b68cefa

Browse files
committed
bug #42289 [HttpFoundation] Fixed type mismatch (Toflar)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Fixed type mismatch | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #42290 | License | MIT | Doc PR | - Fixes > Argument 1 passed to str_contains() must be of the type string, null given, called in /.../vendor/symfony/http-foundation/Response.php on line 327 in case there's no `cache-control` response header. This doesn't happen by default as the `Response` is initialized with one by default but any class extending from it can adjust that. Technically speaking, it's not disallowed to have no `cache-control` header set. Want me to add a test for that? :) Commits ------- 31591c3 [HttpFoundation] Fixed type mismatch
2 parents 1ab8a0e + 31591c3 commit b68cefa

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public function prepare(Request $request)
311311
}
312312

313313
// Check if we need to send extra expire info headers
314-
if ('1.0' == $this->getProtocolVersion() && str_contains($headers->get('Cache-Control'), 'no-cache')) {
314+
if ('1.0' == $this->getProtocolVersion() && str_contains($headers->get('Cache-Control', ''), 'no-cache')) {
315315
$headers->set('pragma', 'no-cache');
316316
$headers->set('expires', -1);
317317
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,12 @@ public function testPrepareSetsPragmaOnHttp10Only()
578578
$this->assertEquals('no-cache', $response->headers->get('pragma'));
579579
$this->assertEquals('-1', $response->headers->get('expires'));
580580

581+
$response = new Response('foo');
582+
$response->headers->remove('cache-control');
583+
$response->prepare($request);
584+
$this->assertFalse($response->headers->has('pragma'));
585+
$this->assertFalse($response->headers->has('expires'));
586+
581587
$request->server->set('SERVER_PROTOCOL', 'HTTP/1.1');
582588
$response = new Response('foo');
583589
$response->prepare($request);

0 commit comments

Comments
 (0)