@ -308,7 +308,7 @@ class Readability implements LoggerAwareInterface
{
{
$this->loadHtml();
$this->loadHtml();
if (!isset($this->dom->documentElement) ) {
if (null === $this->dom || null === $this->dom->documentElement ) {
return false;
return false;
}
}
@ -400,7 +400,7 @@ class Readability implements LoggerAwareInterface
$refLink = $this->dom->createElement('a');
$refLink = $this->dom->createElement('a');
$footnote = $this->dom->createElement('li');
$footnote = $this->dom->createElement('li');
$linkDomain = @parse_url($footnoteLink->getAttribute('href'), \PHP_URL_HOST);
$linkDomain = @parse_url($footnoteLink->getAttribute('href'), \PHP_URL_HOST);
if (!$linkDomain & & isset($this->url) ) {
if (!$linkDomain & & null !== $this->url ) {
$linkDomain = @parse_url($this->url, \PHP_URL_HOST);
$linkDomain = @parse_url($this->url, \PHP_URL_HOST);
}
}
@ -1223,15 +1223,16 @@ class Readability implements LoggerAwareInterface
$topCandidate = $this->dom->createElement('div');
$topCandidate = $this->dom->createElement('div');
if ($page instanceof \DOMDocument) {
if ($page instanceof \DOMDocument) {
if (!isset($page->documentElement)) {
$documentElement = $page->documentElement;
if (null === $documentElement) {
// we don't have a body either? what a mess! :)
// we don't have a body either? what a mess! :)
$this->logger->debug('The page has no body!');
$this->logger->debug('The page has no body!');
} else {
} else {
$this->logger->debug('Setting body to a raw HTML of original page!');
$this->logger->debug('Setting body to a raw HTML of original page!');
$topCandidate->setInnerHtml($page-> documentElement->getInnerHTML());
$topCandidate->setInnerHtml($documentElement->getInnerHTML());
$page-> documentElement->setInnerHtml('');
$documentElement->setInnerHtml('');
$this->reinitBody();
$this->reinitBody();
$page-> documentElement->appendChild($topCandidate);
$documentElement->appendChild($topCandidate);
}
}
} else {
} else {
$topCandidate->setInnerHtml($page->getInnerHTML());
$topCandidate->setInnerHtml($page->getInnerHTML());
@ -1457,7 +1458,7 @@ class Readability implements LoggerAwareInterface
*/
*/
protected function reinitBody(): void
protected function reinitBody(): void
{
{
if (!isset($this->body->childNodes) ) {
if (null === $this->body ) {
$this->body = $this->dom->createElement('body');
$this->body = $this->dom->createElement('body');
$this->body->setInnerHtml($this->bodyCache);
$this->body->setInnerHtml($this->bodyCache);
}
}