From 6d92441ee9e9b4ac387e6041999a0dd7728996ed Mon Sep 17 00:00:00 2001 From: Marek Ognicki Date: Fri, 25 Jun 2021 14:13:51 +0200 Subject: [PATCH 1/2] Fix for in-page absolute favicon paths --- src/Favicon/Favicon.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Favicon/Favicon.php b/src/Favicon/Favicon.php index 329486a..3a66587 100644 --- a/src/Favicon/Favicon.php +++ b/src/Favicon/Favicon.php @@ -151,6 +151,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) @@ -208,7 +209,14 @@ 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] === '/') { + $parsed = parse_url($url); + $favicon = $parsed['scheme'] . '://' . $parsed['host'] . $favicon; + } else { + $favicon = rtrim($url, '/') . '/' . ltrim($favicon, '/'); + } } // Sometimes people lie, so check the status. From 7f645f412ed05fd46a5933cb8af85f7cb502ad44 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 21 Oct 2023 20:09:33 -0400 Subject: [PATCH 2/2] Use existing baseUrl function instead of parse_url --- src/Favicon/Favicon.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Favicon/Favicon.php b/src/Favicon/Favicon.php index 3a66587..4f6f6f4 100644 --- a/src/Favicon/Favicon.php +++ b/src/Favicon/Favicon.php @@ -209,11 +209,9 @@ private function getFavicon($url, $checkDefault = true) // Make sure the favicon is an absolute URL. if ($favicon && filter_var($favicon, FILTER_VALIDATE_URL) === false) { - // Make sure that favicons starting with "/" get concatenated with host instead of full URL if($favicon[0] === '/') { - $parsed = parse_url($url); - $favicon = $parsed['scheme'] . '://' . $parsed['host'] . $favicon; + $favicon = $this->baseUrl($url) . ltrim($favicon, '/'); } else { $favicon = rtrim($url, '/') . '/' . ltrim($favicon, '/'); }