From 5d64e2f21e688afd1f3077201a77acfdb3e2bbac Mon Sep 17 00:00:00 2001 From: Athou Date: Sun, 2 Aug 2026 07:26:44 +0200 Subject: [PATCH] correctly handle root favicons for non-default ports --- .../backend/favicon/RootFaviconFetcher.java | 7 ++++++- .../favicon/RootFaviconFetcherTest.java | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java b/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java index 4e2e6699..20190a40 100644 --- a/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java +++ b/commafeed-server/src/main/java/com/commafeed/backend/favicon/RootFaviconFetcher.java @@ -30,7 +30,12 @@ public class RootFaviconFetcher implements FaviconFetcher { try { URI uri = URI.create(url.trim()); - String faviconUrl = "%s://%s/favicon.ico".formatted(uri.getScheme(), uri.getHost()); + String faviconUrl = + "%s://%s%s/favicon.ico" + .formatted( + uri.getScheme(), + uri.getHost(), + uri.getPort() > 0 ? ":" + uri.getPort() : ""); log.debug("getting root icon at {}", faviconUrl); HttpResult result = getter.get(faviconUrl); diff --git a/commafeed-server/src/test/java/com/commafeed/backend/favicon/RootFaviconFetcherTest.java b/commafeed-server/src/test/java/com/commafeed/backend/favicon/RootFaviconFetcherTest.java index 662361e1..6b117050 100644 --- a/commafeed-server/src/test/java/com/commafeed/backend/favicon/RootFaviconFetcherTest.java +++ b/commafeed-server/src/test/java/com/commafeed/backend/favicon/RootFaviconFetcherTest.java @@ -47,6 +47,26 @@ class RootFaviconFetcherTest { Assertions.assertTrue(result.mediaType().isCompatible(MediaType.valueOf(contentType))); } + @Test + void testFetchUsesLinkWhenAvailableWithNonDefaultPort() throws Exception { + Feed feed = new Feed(); + feed.setUrl("https://feeds.example.com:8000/feed"); + feed.setLink("https://www.example.com:8000/blog"); + + byte[] iconBytes = new byte[1000]; + String contentType = "image/x-icon"; + HttpResult httpResult = + new HttpResult(iconBytes, contentType, null, null, null, Duration.ZERO); + Mockito.when(httpGetter.get("https://www.example.com:8000/favicon.ico")) + .thenReturn(httpResult); + + Favicon result = faviconFetcher.fetch(feed); + + Assertions.assertNotNull(result); + Assertions.assertEquals(iconBytes, result.icon()); + Assertions.assertTrue(result.mediaType().isCompatible(MediaType.valueOf(contentType))); + } + @Test void testFetchFallsBackToUrlWhenLinkIsNull() throws Exception { Feed feed = new Feed();