Skip to content

Commit 947abb1

Browse files
committed
[HttpFoundation][HttpKernel] Fix deprecations when Content-Type is null
1 parent f66be27 commit 947abb1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Response.php

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 0 deletions
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)