Skip to content

Commit

Permalink
Merge pull request #8 from mbiencinto/feature/SR-78
Browse files Browse the repository at this point in the history
[SR-78] - fix request with extension not html and content-type text/html
  • Loading branch information
mbiencinto authored Dec 18, 2020
2 parents ddb4d23 + 9659af1 commit 6be060d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion EventSubscriber/AmpOptimizerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/EventSubscriber/AmpOptimizerSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public function testNotAmpRequest()
$event = $this->getEventNotAmpRequestMocked('text/html', '<html></html>');
$instance->onKernelResponse($event);

$event = $this->getEventNotAmpRequestMocked('text/html', '<body></body>');
$instance->onKernelResponse($event);

$event = $this->getEventNotAmpRequestMocked('text/html', '');
$instance->onKernelResponse($event);
}
Expand Down

0 comments on commit 6be060d

Please sign in to comment.