Skip to content

Commit

Permalink
Merge pull request #21 from mwognicki/master
Browse files Browse the repository at this point in the history
Fix for in-page absolute favicon paths
  • Loading branch information
ArthurHoaro authored Oct 22, 2023
2 parents a635bb5 + 7f645f4 commit b5e4a52
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Favicon/Favicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public function get($url = '', $type = FaviconDLType::HOTLINK_URL)
// Get the base URL without the path for clearer concatenations.
$url = rtrim($this->baseUrl($this->url, true), '/');
$original = $url;

if (
($favicon = $this->checkCache($original, self::$TYPE_CACHE_URL)) === false
&& ! $favicon = $this->getFavicon($original, false)
Expand Down Expand Up @@ -212,7 +213,12 @@ private function getFavicon($url, $checkDefault = true)

// Make sure the favicon is an absolute URL.
if ($favicon && filter_var($favicon, FILTER_VALIDATE_URL) === false) {
$favicon = rtrim($url, '/') . '/' . ltrim($favicon, '/');
// Make sure that favicons starting with "/" get concatenated with host instead of full URL
if($favicon[0] === '/') {
$favicon = $this->baseUrl($url) . ltrim($favicon, '/');
} else {
$favicon = rtrim($url, '/') . '/' . ltrim($favicon, '/');
}
}

// Sometimes people lie, so check the status.
Expand Down

0 comments on commit b5e4a52

Please sign in to comment.