Skip to content

Commit 14e3fad

Browse files
committed
[HttpFoundation][HttpKernel] Fix deprecations when Content-Type is null
1 parent 44b589a commit 14e3fad

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

DataCollector/DumpDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ public function collect(Request $request, Response $response, \Throwable $except
116116
if (!$this->requestStack
117117
|| !$response->headers->has('X-Debug-Token')
118118
|| $response->isRedirection()
119-
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type'), 'html'))
119+
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type') ?? '', 'html'))
120120
|| 'html' !== $request->getRequestFormat()
121121
|| false === strripos($response->getContent(), '</body>')
122122
) {
123-
if ($response->headers->has('Content-Type') && str_contains($response->headers->get('Content-Type'), 'html')) {
123+
if ($response->headers->has('Content-Type') && str_contains($response->headers->get('Content-Type') ?? '', 'html')) {
124124
$dumper = new HtmlDumper('php://output', $this->charset);
125125
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
126126
} else {

Tests/DataCollector/DumpDataCollectorTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\RequestStack;
1617
use Symfony\Component\HttpFoundation\Response;
1718
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
1819
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
@@ -152,4 +153,22 @@ public function testFlushNothingWhenDataDumperIsProvided()
152153
$collector->__destruct();
153154
$this->assertEmpty(ob_get_clean());
154155
}
156+
157+
public function testNullContentTypeWithNoDebugEnv()
158+
{
159+
$request = new Request();
160+
$requestStack = new RequestStack();
161+
$requestStack->push($request);
162+
163+
$response = new Response('<html><head></head><body></body></html>');
164+
$response->headers->set('Content-Type', null);
165+
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
166+
167+
$collector = new DumpDataCollector(null, null, null, $requestStack);
168+
$collector->collect($request, $response);
169+
170+
ob_start();
171+
$collector->__destruct();
172+
$this->assertEmpty(ob_get_clean());
173+
}
155174
}

0 commit comments

Comments
 (0)