summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/HTMLParser.php2
2 files changed, 2 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c6da72d..e1c9222 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
- Trim titles when detecting hierarchical separators to avoid false negatives on strings with spaces.
- Fix issue when converting divs to p nodes and never rating them (issue #29)
- Fix "Unsupported operand types" (PR #31)
+- Fix division by zero when no title was found (issue #32)
## [v0.3.0](https://github.com/andreskrey/readability.php/releases/tag/v0.3.0)
diff --git a/src/HTMLParser.php b/src/HTMLParser.php
index 9dff4bd..9c570ba 100644
--- a/src/HTMLParser.php
+++ b/src/HTMLParser.php
@@ -1099,7 +1099,7 @@ class HTMLParser
*/
$h2 = $article->getElementsByTagName('h2');
if ($h2->length === 1) {
- $lengthSimilarRate = (mb_strlen($h2->item(0)->textContent) - mb_strlen($this->metadata['title'])) / mb_strlen($this->metadata['title']);
+ $lengthSimilarRate = (mb_strlen($h2->item(0)->textContent) - mb_strlen($this->metadata['title'])) / max(mb_strlen($this->metadata['title']), 1);
if (abs($lengthSimilarRate) < 0.5) {
if ($lengthSimilarRate > 0) {