From ec7fb4d8504118d918699d5df8cd07c91af2f9b3 Mon Sep 17 00:00:00 2001 From: "FiveFilters.org" Date: Tue, 28 Dec 2021 17:16:05 +0100 Subject: Fixes Reported here: https://forum.fivefilters.org/t/readability-php-fatal-error/1283 --- src/Readability.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Readability.php b/src/Readability.php index 5c8fb84..6407a92 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -250,6 +250,11 @@ class Readability } } + if (!$result) { + $this->logger->info('*** Parse failed :('); + return false; + } + $result = $this->postProcessContent($result); // If we haven't found an excerpt in the article's metadata, use the article's @@ -369,6 +374,7 @@ class Readability $metadata = []; if ( !isset($parsed['@context']) || + !is_string($parsed['@context']) || !preg_match('/^https?\:\/\/schema\.org$/', $parsed['@context']) ) { return $metadata; @@ -2137,6 +2143,9 @@ class Readability if ($node->nodeName !== 'h1' && $node->nodeName !== 'h2') { return false; } + if (!isset($this->title)) { + return false; + } $heading = $node->getTextContent(false); $this->logger->debug(sprintf('Evaluating similarity of header: %s"', $heading)); return $this->textSimilarity($this->title, $heading) > 0.75; -- cgit v1.2.3