Skip to content

Commit 2e8ebca

Browse files
peterrehmfabpot
authored andcommitted
Do not inject web debug toolbar on attachments
1 parent f870ddc commit 2e8ebca

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

EventListener/WebDebugToolbarListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function onKernelResponse(FilterResponseEvent $event)
9898
|| $response->isRedirection()
9999
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
100100
|| 'html' !== $request->getRequestFormat()
101+
|| false !== stripos($response->headers->get('Content-Disposition'), 'attachment;')
101102
) {
102103
return;
103104
}

Tests/EventListener/WebDebugToolbarListenerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ public function testToolbarIsInjected()
8282
$this->assertEquals("<html><head></head><body>\nWDT\n</body></html>", $response->getContent());
8383
}
8484

85+
/**
86+
* @depends testToolbarIsInjected
87+
*/
88+
public function testToolbarIsNotInjectedOnContentDispositionAttachment()
89+
{
90+
$response = new Response('<html><head></head><body></body></html>');
91+
$response->headers->set('Content-Disposition', 'attachment; filename=test.html');
92+
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'html'), HttpKernelInterface::MASTER_REQUEST, $response);
93+
94+
$listener = new WebDebugToolbarListener($this->getTwigMock());
95+
$listener->onKernelResponse($event);
96+
97+
$this->assertEquals('<html><head></head><body></body></html>', $response->getContent());
98+
}
99+
85100
/**
86101
* @depends testToolbarIsInjected
87102
* @dataProvider provideRedirects

0 commit comments

Comments
 (0)