Skip to content

Commit

Permalink
Use empty string instead of relative URL if resolving against base fails
Browse files Browse the repository at this point in the history
  • Loading branch information
fivefilters committed Apr 21, 2024
1 parent 47e60c2 commit 4587fea
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Readability.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public function getImages(): array
try {
$imgSrc = $this->toAbsoluteURI($imgSrc);
} catch (\Exception $err) {
// Invalid URL, leave as is
$imgSrc = '';
}
}
}
Expand Down Expand Up @@ -637,7 +637,7 @@ public function getMainImage()
try {
$this->setImage($this->toAbsoluteURI($imgUrl));
} catch (\Exception $err) {
// Invalid URL, leave as is
$this->setImage(null);
}
}
}
Expand Down Expand Up @@ -2167,7 +2167,7 @@ private function headerDuplicatesTitle($node) {
* Readability.js has a special filter to avoid cleaning the classes that the algorithm adds. We don't add classes
* here so no need to filter those.
*
* @param DOMDocument|DOMNode $node
* @param DOMDocument|DOMNode|DOMElement $node
*
* @return void
**/
Expand Down Expand Up @@ -2244,6 +2244,7 @@ public function postProcessContent(DOMDocument $article)
$media->setAttribute('src', $this->toAbsoluteURI($src));
} catch (\Exception $err) {
$this->logger->debug('[PostProcess] Invalid URL encountered');
$media->setAttribute('src', '');
}
}

Expand All @@ -2254,6 +2255,7 @@ public function postProcessContent(DOMDocument $article)
$media->setAttribute('poster', $this->toAbsoluteURI($poster));
} catch (\Exception $err) {
$this->logger->debug('[PostProcess] Invalid URL encountered');
$media->setAttribute('poster', '');
}

}
Expand All @@ -2264,6 +2266,7 @@ public function postProcessContent(DOMDocument $article)
try {
return $this->toAbsoluteURI($matches[1]) . $matches[2] . $matches[3];
} catch (\Exception $err) {
// Leave as is
return $matches[1] . $matches[2] . $matches[3];
}
}, $srcset);
Expand Down Expand Up @@ -2377,17 +2380,17 @@ public function setExcerpt($excerpt)
}

/**
* @return string|null
* Get main image
*/
public function getImage()
public function getImage(): ?string
{
return $this->image;
}

/**
* @param string $image
* Set main image
*/
protected function setImage($image)
protected function setImage(?string $image)
{
$this->image = $image;
}
Expand Down

0 comments on commit 4587fea

Please sign in to comment.