Skip to content

Commit

Permalink
Fixed empty document after importing invalid HTML
Browse files Browse the repository at this point in the history
- The library will now emit a warning and load the invalid HTML as a plain string
  • Loading branch information
PerryRylance committed Dec 26, 2020
1 parent 718e6a9 commit b2c42c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/class.dom-document.php
Expand Up @@ -100,6 +100,14 @@ public function loadHTML($src, $options=array())
]);
$html5->loadHTML($src, $options);

if($html5->hasErrors())
{
foreach($html5->getErrors() as $err)
trigger_error($err, E_USER_WARNING);

Parent::loadHTML($src);
}

return $this;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/test.php
Expand Up @@ -6,6 +6,15 @@
use \PerryRylance\DOMDocument as DOMDocument;

$document = new DOMDocument();

// start temp

$document->loadHTML("This here is a test. It's not valid HTML");
var_dump($document->html);
exit;

// end temp

$document->load("sample.html");

$tests = [
Expand Down

0 comments on commit b2c42c4

Please sign in to comment.