Skip to content

Commit 415a1f8

Browse files
minor #51032 [HttpFoundation][HttpKernel] Fix deprecations when Content-Type is null (HypeMC)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpFoundation][HttpKernel] Fix deprecations when `Content-Type` is `null` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Followup to #51000. Two more places I discovered were triggering deprecations when `Content-Type` is `null`. Commits ------- 678d7be1b3 [HttpFoundation][HttpKernel] Fix deprecations when `Content-Type` is `null`
2 parents 0c29a60 + 947abb1 commit 415a1f8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Response.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public function prepare(Request $request)
298298
$charset = $this->charset ?: 'UTF-8';
299299
if (!$headers->has('Content-Type')) {
300300
$headers->set('Content-Type', 'text/html; charset='.$charset);
301-
} elseif (0 === stripos($headers->get('Content-Type'), 'text/') && false === stripos($headers->get('Content-Type'), 'charset')) {
301+
} elseif (0 === stripos($headers->get('Content-Type') ?? '', 'text/') && false === stripos($headers->get('Content-Type') ?? '', 'charset')) {
302302
// add the charset
303303
$headers->set('Content-Type', $headers->get('Content-Type').'; charset='.$charset);
304304
}

Tests/ResponseTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,16 @@ public function testContentTypeCharset()
511511
$this->assertEquals('text/css; charset=UTF-8', $response->headers->get('Content-Type'));
512512
}
513513

514+
public function testContentTypeIsNull()
515+
{
516+
$response = new Response('foo');
517+
$response->headers->set('Content-Type', null);
518+
519+
$response->prepare(new Request());
520+
521+
$this->expectNotToPerformAssertions();
522+
}
523+
514524
public function testPrepareDoesNothingIfContentTypeIsSet()
515525
{
516526
$response = new Response('foo');

0 commit comments

Comments
 (0)