From 0a39fc1a3a75ce1be632cad20d7b271491395073 Mon Sep 17 00:00:00 2001
From: Peter Rehm
Date: Sun, 5 Jun 2016 18:33:19 +0200
Subject: [PATCH 1/4] Do not inject toolbar if content disposition header
attachment is defined
---
.../EventListener/WebDebugToolbarListener.php | 5 +++++
.../EventListener/WebDebugToolbarListenerTest.php | 15 +++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php
index ee537af4f9889..a07615d42dcbe 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php
+++ b/src/Symfony/Bundle/WebProfilerBundle/EventListener/WebDebugToolbarListener.php
@@ -112,6 +112,11 @@ public function onKernelResponse(FilterResponseEvent $event)
*/
protected function injectToolbar(Response $response, Request $request)
{
+ // The toolbar shall not be injected if the header enforces a download of the content
+ if (false !== strpos($response->headers->get('Content-Disposition'), 'attachment')) {
+ return;
+ }
+
$content = $response->getContent();
$pos = strripos($content, '
\nWDT\n');
diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php
index e5d95471ae09f..f5aa3f4ab8531 100644
--- a/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php
+++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/EventListener/WebDebugToolbarListenerTest.php
@@ -82,6 +82,21 @@ public function testToolbarIsInjected()
$this->assertEquals("