Skip to content

Commit

Permalink
Bug fixes for issue #12
Browse files Browse the repository at this point in the history
  • Loading branch information
fivefilters committed Jan 14, 2023
1 parent df4d880 commit c259830
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Readability.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function parse($html)
* finding the -right- content.
*/

$length = mb_strlen(preg_replace(NodeUtility::$regexps['onlyWhitespace'], '', $result->textContent));
$length = !$result ? 0 : mb_strlen(preg_replace(NodeUtility::$regexps['onlyWhitespace'], '', $result->textContent));

$this->logger->info(sprintf('[Parsing] Article parsed. Amount of words: %s. Current threshold is: %s', $length, $this->configuration->getCharThreshold()));

Expand Down Expand Up @@ -1503,15 +1503,15 @@ private function rateNodes($nodes)
$siblingScoreThreshold = max(10, $topCandidate->contentScore * 0.2);
// Keep potential top candidate's parent node to try to get text direction of it later.
$parentOfTopCandidate = $topCandidate->parentNode;
$siblings = $parentOfTopCandidate->childNodes;
$siblings = $parentOfTopCandidate->childNodes ?? null;

$hasContent = false;

$this->logger->info('[Rating] Adding top candidate siblings...');

/* @var DOMElement $sibling */
// Can't foreach here because down there we might change the tag name and that causes the foreach to skip items
for ($i = 0; $i < $siblings->length; $i++) {
for ($i = 0; $i < $siblings->length ?? 0; $i++) {
$sibling = $siblings[$i];
$append = false;

Expand Down

0 comments on commit c259830

Please sign in to comment.