ampproject / amp-toolbox-php

AMP Optimizer PHP library
Apache License 2.0
74 stars 23 forks source link

Fix error when source is missing closing head tag #524

Closed ediamin closed 2 years ago

ediamin commented 2 years ago

Fixes #522

This PR fixes the uncaught DOMException: Not Found Error when the Document class tries to load a source that has no closing head and body tags and contains invalid node in the head tag. For example,

<html><head><meta name="foo" content="bar"><foo></foo><bar></bar>

With this fix, we will get a proper structured html like this,

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="foo" content="bar" />
  </head>
  <body>
    <foo></foo><bar></bar>
  </body>
</html>