Skip to content

Commit

Permalink
Do not inject web debug toolbar on attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrehm authored and fabpot committed Jun 8, 2016
1 parent a004fc7 commit 4a7d836
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function onKernelResponse(FilterResponseEvent $event)
|| $response->isRedirection()
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
|| 'html' !== $request->getRequestFormat()
|| false !== stripos($response->headers->get('Content-Disposition'), 'attachment;')
) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ public function testToolbarIsInjected()
$this->assertEquals("<html><head></head><body>\nWDT\n</body></html>", $response->getContent());
}

/**
* @depends testToolbarIsInjected
*/
public function testToolbarIsNotInjectedOnContentDispositionAttachment()
{
$response = new Response('<html><head></head><body></body></html>');
$response->headers->set('Content-Disposition', 'attachment; filename=test.html');
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html'), HttpKernelInterface::MASTER_REQUEST, $response);

$listener = new WebDebugToolbarListener($this->getTwigMock());
$listener->onKernelResponse($event);

$this->assertEquals('<html><head></head><body></body></html>', $response->getContent());
}

/**
* @depends testToolbarIsInjected
* @dataProvider provideRedirects
Expand Down

0 comments on commit 4a7d836

Please sign in to comment.