From 9f8942d3f6720488d5c32ee6dedc0bdc3020f3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Humeau?= Date: Fri, 28 Oct 2016 11:54:54 +0200 Subject: [PATCH] Inject Alertify only if Response has a body, don't have a meta refresh and is not a RedirectResponse (#51) Inject Alertify only if Response has a body, don't have a meta refresh and is not a RedirectResponse --- EventListener/AlertifyListener.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/EventListener/AlertifyListener.php b/EventListener/AlertifyListener.php index ec2c9d0..51008ba 100644 --- a/EventListener/AlertifyListener.php +++ b/EventListener/AlertifyListener.php @@ -63,11 +63,14 @@ protected function injectAlertify(Response $response, Request $request) } $content = $response->getContent(); - $pos = strripos($content, ''); + $endBodyPos = strripos($content, ''); + $hasBody = false !== $endBodyPos; + $hasMetaRefresh = false !== strripos($content, 'http-equiv="refresh"'); + $isRedirectResponse = $response instanceof RedirectResponse; - if (false !== $pos) { + if ($hasBody && !$hasMetaRefresh && !$isRedirectResponse) { $alertify = $this->alertifySessionHandler->handle($this->session); - $content = substr($content, 0, $pos).$alertify.substr($content, $pos); + $content = substr($content, 0, $endBodyPos).$alertify.substr($content, $endBodyPos); $response->setContent($content); } }