Skip to content

Commit

Permalink
Merge 1ed2a69 into 26d98bb
Browse files Browse the repository at this point in the history
  • Loading branch information
mhujer committed Nov 24, 2019
2 parents 26d98bb + 1ed2a69 commit 21c0a9b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ java_script_error_handler:

Requirements
------------
PHP 7.1 or higher and Symfony 3.3+.
PHP 7.2 or higher and Symfony 4.3+.


Author
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
],
"require": {
"php": "~7.2",
"symfony/config": "^4.2",
"symfony/dependency-injection": "^4.2",
"symfony/event-dispatcher": "^4.2",
"symfony/expression-language": "^4.2",
"symfony/http-foundation": "^4.2",
"symfony/http-kernel": "^4.2"
"symfony/config": "^4.3",
"symfony/dependency-injection": "^4.3",
"symfony/event-dispatcher": "^4.3",
"symfony/expression-language": "^4.3",
"symfony/http-foundation": "^4.3.4",
"symfony/http-kernel": "^4.3"
},
"require-dev": {
"consistence/coding-standard": "3.5",
Expand Down
4 changes: 4 additions & 0 deletions src/EventListener/JsErrorToAlertListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function onKernelResponse(FilterResponseEvent $event): void
protected function injectScript(Response $response, Request $request): void
{
$content = $response->getContent();
if ($content === false) {
return;
}

$pos = stripos($content, '<head>');

if ($pos !== false) {
Expand Down
18 changes: 18 additions & 0 deletions tests/EventListener/JsErrorToAlertListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Kernel;
Expand Down Expand Up @@ -134,6 +135,23 @@ public function redirectCodesDataProvider(): array
];
}

public function testScriptIsNotInjectedToStreamedResponse(): void
{
$response = new StreamedResponse();

$event = new FilterResponseEvent(
$this->getKernelMock(),
$this->getRequestMock(),
HttpKernelInterface::MASTER_REQUEST,
$response
);

$listener = new JsErrorToAlertListener();
$listener->onKernelResponse($event);

$this->assertFalse($response->getContent());
}

public function testScriptIsNotInjectedOnSubRequest(): void
{
$response = new Response(self::BASIC_HTML);
Expand Down

0 comments on commit 21c0a9b

Please sign in to comment.