bug #18971 Do not inject web debug toolbar on attachments (peterrehm)
This PR was squashed before being merged into the 2.7 branch (closes #18971).
Discussion
----------
Do not inject web debug toolbar on attachments
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #18965
| License | MIT
| Doc PR | -
Commits
-------
4a7d836
Do not inject web debug toolbar on attachments
This commit is contained in:
commit
a81b6cec5d
@ -98,6 +98,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
|
||||
|| $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;
|
||||
}
|
||||
|
@ -82,6 +82,21 @@ class WebDebugToolbarListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$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
|
||||
|
Reference in New Issue
Block a user