summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFiveFilters.org <[email protected]>2021-12-28 17:16:05 +0100
committerFiveFilters.org <[email protected]>2021-12-28 17:16:05 +0100
commitec7fb4d8504118d918699d5df8cd07c91af2f9b3 (patch)
treef7ddb74eb1b1517bf3781db18ba9714edff6be8d
parent414a16008658448850647dc43d5012194ce495f3 (diff)
Fixes
Reported here: https://forum.fivefilters.org/t/readability-php-fatal-error/1283
-rw-r--r--src/Readability.php9
1 files changed, 9 insertions, 0 deletions
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;