Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Fix favicons for domains including a subfolder (#5258)

RobertJoonas7e248d07ca87
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8a5648e2ac..b9acda0634 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,7 @@ All notable changes to this project will be documented in this file.
### Fixed
+- Fix fetching favicons from DuckDuckGo when the domain includes a pathname
- Fix `visitors.csv` (in dashboard CSV export) vs dashboard main graph reporting different results for `visitors` and `visits` with a `time:minute` interval.
- The tracker script now sends pageviews when a page gets loaded from bfcache
- Fix returning filter suggestions for multiple custom property values in the dashboard Filter modal
diff --git a/lib/plausible_web/plugs/favicon.ex b/lib/plausible_web/plugs/favicon.ex
index 755e754dc9..b5c0f49e5f 100644
--- a/lib/plausible_web/plugs/favicon.ex
+++ b/lib/plausible_web/plugs/favicon.ex
@@ -94,9 +94,13 @@ defmodule PlausibleWeb.Favicon do
"/favicon/sources/placeholder" ->
send_placeholder(conn)
- "/favicon/sources/" <> source ->
- clean_source = URI.decode_www_form(source)
- domain = Map.get(favicon_domains, clean_source, clean_source)
+ "/favicon/sources/" <> domain ->
+ domain = URI.decode_www_form(domain)
+
+ domain =
+ Map.get(favicon_domains, domain, domain)
+ |> String.split("/", parts: 2)
+ |> hd()
case HTTPClient.impl().get("https://icons.duckduckgo.com/ip3/#{domain}.ico") do
{:ok, %Finch.Response{status: 200, body: body, headers: headers}}
diff --git a/test/plausible_web/plugs/favicon_test.exs b/test/plausible_web/plugs/favicon_test.exs
index 45f93d457d..064c52f7fe 100644
--- a/test/plausible_web/plugs/favicon_test.exs
+++ b/test/plausible_web/plugs/favicon_test.exs
@@ -38,11 +38,11 @@ defmodule PlausibleWeb.FaviconTest do
assert conn.resp_body == "favicon response body"
end
- test "requests favicon from DDG when domain contains a forward slash", %{plug_opts: plug_opts} do
+ test "requests favicon from DDG by hostname only (strips pathname)", %{plug_opts: plug_opts} do
expect(
Plausible.HTTPClient.Mock,
:get,
- fn "https://icons.duckduckgo.com/ip3/site.com/subfolder.ico" ->
+ fn "https://icons.duckduckgo.com/ip3/site.com.ico" ->
{:ok, %Finch.Response{status: 200, body: "favicon response body"}}
end
)