diff --git a/README.md b/README.md index 1d354c9..dc230b3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/composer.json b/composer.json index cdd7b6b..f8283c1 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/EventListener/JsErrorToAlertListener.php b/src/EventListener/JsErrorToAlertListener.php index f71672b..b50fdbe 100644 --- a/src/EventListener/JsErrorToAlertListener.php +++ b/src/EventListener/JsErrorToAlertListener.php @@ -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, ''); if ($pos !== false) { diff --git a/tests/EventListener/JsErrorToAlertListenerTest.php b/tests/EventListener/JsErrorToAlertListenerTest.php index b7284cf..07801b9 100644 --- a/tests/EventListener/JsErrorToAlertListenerTest.php +++ b/tests/EventListener/JsErrorToAlertListenerTest.php @@ -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; @@ -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);