Skip to content

Commit

Permalink
fix(PreviewBarSubscriber): Test if Response content is string before …
Browse files Browse the repository at this point in the history
…searching </body> tag
  • Loading branch information
ambroisemaupate committed Apr 6, 2023
1 parent d265a9c commit 93d1897
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ public function onKernelResponse(ResponseEvent $event): void
{
if ($this->supports($event)) {
$response = $event->getResponse();
$content = $response->getContent();
if (
str_contains($response->getContent(), '</body>') &&
str_contains($response->getContent(), '</head>')
is_string($content) &&
str_contains($content, '</body>') &&
str_contains($content, '</head>')
) {
$content = str_replace(
'</head>',
"<style>#roadiz-preview-bar { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen-Sans, Ubuntu, Cantarell, \"Helvetica Neue\", Helvetica, Arial, sans-serif; position: fixed; display: inline-flex; align-items: center; font-size: 9px; padding: 6px 10px 5px; bottom: 0; left: 1em; background-color: #ffe200; color: #923f00; border-radius: 3px 3px 0 0; text-transform: uppercase; letter-spacing: 0.005em; z-index: 9999;} #roadiz-preview-bar svg { width: 14px; margin-right: 5px;}</style></head>",
$response->getContent()
$content
);
$content = str_replace(
'</body>',
Expand Down

0 comments on commit 93d1897

Please sign in to comment.