Skip to content

Commit

Permalink
fixing injection middleware with preg_replace
Browse files Browse the repository at this point in the history
  • Loading branch information
devajmeireles committed Sep 17, 2024
1 parent 619b039 commit 1da847a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/Middleware/Injection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public function handle($request, Closure $next) // @pest-ignore-type
return $next($request);
}

return app(Render::class)->handle($next($request));
$response = $next($request);

return app(Render::class)->handle($response);
}
}
14 changes: 1 addition & 13 deletions src/Response/ResponseHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,7 @@ public function __invoke(): Response
$content = substr_replace($content, $this->render->js(), $head + 6, 0);
}

if (($start = strpos($content, '<body')) !== false) {
$end = strpos($content, '">', $start);

if ($end !== false) {
$content = substr_replace($content, $this->render->component(), $end + 3, 0);
} else {
$end = strpos($content, '>', $start);

if ($end !== false) {
$content = substr_replace($content, $this->render->component(), $end + 2, 0);
}
}
}
$content = preg_replace('/(<body[^>]*>)/i', '$1'.$this->render->component(), $content);

Check failure on line 26 in src/Response/ResponseHandle.php

View workflow job for this annotation

GitHub Actions / OS:ubuntu-latest / PHP:8.2 / Laravel:11.*

Binary operation "." between '$1' and Illuminate\Contracts\View\View results in an error.

Check failure on line 26 in src/Response/ResponseHandle.php

View workflow job for this annotation

GitHub Actions / OS:ubuntu-latest / PHP:8.3 / Laravel:11.*

Binary operation "." between '$1' and Illuminate\Contracts\View\View results in an error.

return $this->response->setContent($content);
}
Expand Down

0 comments on commit 1da847a

Please sign in to comment.