diff --git a/EventSubscriber/AmpOptimizerSubscriber.php b/EventSubscriber/AmpOptimizerSubscriber.php index 3a35597..806f835 100644 --- a/EventSubscriber/AmpOptimizerSubscriber.php +++ b/EventSubscriber/AmpOptimizerSubscriber.php @@ -118,7 +118,12 @@ private function isAmpHtml(Response $response, Request $request): bool return false; } - $htmlElementAttrs = $dom->find('html', 0)->getAllAttributes(); + $htmlElement = $dom->find('html', 0); + if (null === $htmlElement) { + return false; + } + + $htmlElementAttrs = $htmlElement->getAllAttributes(); if (empty(array_intersect(['⚡', 'amp'], array_keys($htmlElementAttrs)))) { return false; } diff --git a/Tests/Unit/EventSubscriber/AmpOptimizerSubscriberTest.php b/Tests/Unit/EventSubscriber/AmpOptimizerSubscriberTest.php index d5fd18e..b4ae227 100644 --- a/Tests/Unit/EventSubscriber/AmpOptimizerSubscriberTest.php +++ b/Tests/Unit/EventSubscriber/AmpOptimizerSubscriberTest.php @@ -91,6 +91,9 @@ public function testNotAmpRequest() $event = $this->getEventNotAmpRequestMocked('text/html', ''); $instance->onKernelResponse($event); + $event = $this->getEventNotAmpRequestMocked('text/html', ''); + $instance->onKernelResponse($event); + $event = $this->getEventNotAmpRequestMocked('text/html', ''); $instance->onKernelResponse($event); }