summaryrefslogtreecommitdiff
path: root/src/Readability.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Readability.php')
-rw-r--r--src/Readability.php4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/Readability.php b/src/Readability.php
index d69897b..b8b5b5b 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -983,7 +983,9 @@ class Readability
// and whose scores are quite closed with current `topCandidate` node.
$alternativeCandidateAncestors = [];
for ($i = 1; $i < count($topCandidates); $i++) {
- if ($topCandidates[$i]->contentScore / $topCandidate->contentScore >= 0.75) {
+ // In some cases we may end up with a top candidate with zero content score. To avoid dividing by zero
+ // we have to use max() and replace zero with a low value like 0.1
+ if ($topCandidates[$i]->contentScore / max($topCandidate->contentScore, 0.1) >= 0.75) {
array_push($alternativeCandidateAncestors, $topCandidates[$i]->getNodeAncestors(false));
}
}