Skip to content

Commit d79796b

Browse files
bug symfony#51000 [WebProfilerBundle] Fix error in case of 'Content-Type' set null in dev environment with no debug (alexbuyanow)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [WebProfilerBundle] Fix error in case of 'Content-Type' set null in dev environment with no debug | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#50977 | License | MIT | Doc PR | - Commits ------- 6faed31 [WebProfilerBundle] Fix error in case of 'Content-Type' set null in dev environment with no debug
2 parents 27651a5 + 6faed31 commit d79796b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function onKernelResponse(ResponseEvent $event)
121121
if (self::DISABLED === $this->mode
122122
|| !$response->headers->has('X-Debug-Token')
123123
|| $response->isRedirection()
124-
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type'), 'html'))
124+
|| ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type') ?? '', 'html'))
125125
|| 'html' !== $request->getRequestFormat()
126126
|| false !== stripos($response->headers->get('Content-Disposition', ''), 'attachment;')
127127
) {

src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,20 @@ public function testCspIsKeptEnabledIfDumperWasNotUsed()
344344
$this->assertEquals("<html><head></head><body>\nWDT\n</body></html>", $response->getContent());
345345
}
346346

347+
public function testNullContentTypeWithNoDebugEnv()
348+
{
349+
$response = new Response('<html><head></head><body></body></html>');
350+
$response->headers->set('Content-Type', null);
351+
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
352+
353+
$event = new ResponseEvent($this->createMock(Kernel::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $response);
354+
355+
$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, null);
356+
$listener->onKernelResponse($event);
357+
358+
$this->expectNotToPerformAssertions();
359+
}
360+
347361
protected function getTwigMock($render = 'WDT')
348362
{
349363
$templating = $this->createMock(Environment::class);

0 commit comments

Comments
 (0)