Skip to content

Commit

Permalink
fix: do not request favicon for empty base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Feb 10, 2023
1 parent c913947 commit f55680c
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ protected function buildItem(
* @param FeedInterface $feed Feed to check for a logo
* @param string $url Original URL for the feed
*
* @return string|mixed|bool
* @return string|null
*/
protected function getFavicon(FeedInterface $feed, string $url)
protected function getFavicon(FeedInterface $feed, string $url): ?string
{
$favicon = null;
// trim the string because authors do funny things
Expand All @@ -370,9 +370,15 @@ protected function getFavicon(FeedInterface $feed, string $url)
$base_url->setPath("");
$base_url = $base_url->getNormalizedURL();

// Return if the URL is empty
if ($base_url === null || trim($base_url) === '') {
return null;
}

// check if feed has a logo entry
if (is_null($favicon) || $favicon === '') {
return $this->faviconFactory->get($base_url);
if ($favicon === null || $favicon === '') {
$return = $this->faviconFactory->get($base_url);
return is_string($return) ? $return : null;
}

// logo will be saved in the tmp folder provided by Nextcloud, file is named as md5 of the url
Expand Down Expand Up @@ -424,16 +430,18 @@ protected function getFavicon(FeedInterface $feed, string $url)

// check if file is actually an image
if (!$is_image) {
return $this->faviconFactory->get($base_url);
$return = $this->faviconFactory->get($base_url);
return is_string($return) ? $return : null;
}

list($width, $height, $type, $attr) = getimagesize($favicon_path);
// check if image is square else fall back to favicon
if ($width !== $height) {
return $this->faviconFactory->get($base_url);
$return = $this->faviconFactory->get($base_url);
return is_string($return) ? $return : null;
}

return $favicon;
return is_string($favicon) ? $favicon : null;
}

/**
Expand Down

0 comments on commit f55680c

Please sign in to comment.