From 9659af1b5394ab4eb22cdd359aa32365f0466f9d Mon Sep 17 00:00:00 2001 From: Mariano Biencinto Date: Fri, 18 Dec 2020 12:13:56 +0100 Subject: [PATCH] [SR-78] - fix request with extension not html and content-type text/html --- EventSubscriber/AmpOptimizerSubscriber.php | 7 ++++++- Tests/Unit/EventSubscriber/AmpOptimizerSubscriberTest.php | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) 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); }