Skip to content

Commit

Permalink
Optimized HTML parsing error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed Mar 3, 2017
1 parent b74bb4e commit 1baea9e
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,18 @@ public function createDocumentFromSource($source)
$dom->loadHTML($source, LIBXML_NOWARNING);
$errors = libxml_get_errors();
libxml_use_internal_errors(false);
$this->processParsingErrors($errors);
return $dom;
}

// Run through all errors
/** @var \LibXMLError $error */
/**
* Process parsing errors
*
* @param \LibXMLError[] $errors Parsing errors
* @throws InvalidArgumentException If it's not a HTML5 error
*/
protected function processParsingErrors(array $errors)
{
foreach ($errors as $error) {
if (($error->code != 801) ||
(
Expand All @@ -217,7 +226,5 @@ public function createDocumentFromSource($source)
throw new InvalidArgumentException($error->message, $error->code);
}
}

return $dom;
}
}

0 comments on commit 1baea9e

Please sign in to comment.