Skip to content

Commit 9f8942d

Browse files
gregumolenybernard
authored andcommitted
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
1 parent 79f047a commit 9f8942d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

EventListener/AlertifyListener.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ protected function injectAlertify(Response $response, Request $request)
6363
}
6464

6565
$content = $response->getContent();
66-
$pos = strripos($content, '</body>');
66+
$endBodyPos = strripos($content, '</body>');
67+
$hasBody = false !== $endBodyPos;
68+
$hasMetaRefresh = false !== strripos($content, 'http-equiv="refresh"');
69+
$isRedirectResponse = $response instanceof RedirectResponse;
6770

68-
if (false !== $pos) {
71+
if ($hasBody && !$hasMetaRefresh && !$isRedirectResponse) {
6972
$alertify = $this->alertifySessionHandler->handle($this->session);
70-
$content = substr($content, 0, $pos).$alertify.substr($content, $pos);
73+
$content = substr($content, 0, $endBodyPos).$alertify.substr($content, $endBodyPos);
7174
$response->setContent($content);
7275
}
7376
}

0 commit comments

Comments
 (0)