diff --git a/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift b/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift index 972dc3056..3d273227a 100644 --- a/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift +++ b/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift @@ -53,6 +53,9 @@ private extension SignificantImageFilter { /// Path components of open-tracking and click-tracking URLs on any host. Lowercase. static let blockedPathComponents: Set = ["open", "track"] + /// A URL ending in one of these isn’t blocked by its path components. GIF isn’t included, since it’s the usual format for tracking pixels. + static let photoFileExtensions: Set = ["avif", "heic", "jpeg", "jpg", "png", "webp"] + /// Share buttons, badges, tracking pixels, and placeholders. Hosts include their subdomains. Path prefixes are lowercase. static let blockedImagePrefixes: [HostAndPathPrefix] = [ (host: "addtoany.com", pathPrefix: "/"), @@ -105,7 +108,7 @@ private extension SignificantImageFilter { if blockedFileNames.contains(url.deletingPathExtension().lastPathComponent.lowercased()) { return true } - if url.pathComponents.contains(where: { blockedPathComponents.contains($0.lowercased()) }) { + if !photoFileExtensions.contains(url.pathExtension.lowercased()), url.pathComponents.contains(where: { blockedPathComponents.contains($0.lowercased()) }) { return true } if matches(host: host, path: url.path().lowercased(), blockedImagePrefixes) { diff --git a/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift b/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift index 6899b01f0..f59d36326 100644 --- a/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift +++ b/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift @@ -155,6 +155,8 @@ import RSParser #expect(!SignificantImageFilter.isSignificant(urlString: "https://example.com/banner.jpg", width: 1200, height: 250)) #expect(!SignificantImageFilter.isSignificant(urlString: "https://example.com/images/spacer.gif", width: nil, height: nil)) #expect(!SignificantImageFilter.isSignificant(urlString: "https://email.example.net/open/abc123.gif", width: nil, height: nil)) + #expect(!SignificantImageFilter.isSignificant(urlString: "https://email.example.net/wf/open?upn=abc123", width: nil, height: nil)) + #expect(SignificantImageFilter.isSignificant(urlString: "https://cdn.example.com/track/cover.jpg", width: nil, height: nil)) #expect(SignificantImageFilter.isSignificant(urlString: "https://example.com/2026/open-source-pixel-art.jpg", width: nil, height: nil)) } }