diff --git a/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift b/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift index 3f1651754..c6fb05453 100644 --- a/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift +++ b/Modules/RSParser/Sources/RSParser/HTML/SignificantImageFilter.swift @@ -47,6 +47,12 @@ private extension SignificantImageFilter { static let decorativeClasses: Set = ["emoji", "wp-smiley"] + /// File names, without extension, of tracking pixels and placeholders on any host. Lowercase. + static let blockedFileNames: Set = ["1x1", "blank", "pixel", "spacer", "transparent"] + + /// Path components of open-tracking and click-tracking URLs on any host. Lowercase. + static let blockedPathComponents: Set = ["open", "track"] + /// Share buttons, badges, tracking pixels, and placeholders. Hosts include their subdomains. Path prefixes are lowercase. static let blockedImagePrefixes: [HostAndPathPrefix] = [ (host: "addtoany.com", pathPrefix: "/"), @@ -96,6 +102,12 @@ private extension SignificantImageFilter { if url.pathExtension.lowercased() == "svg" { return true } + if blockedFileNames.contains(url.deletingPathExtension().lastPathComponent.lowercased()) { + return true + } + if url.pathComponents.contains(where: { blockedPathComponents.contains($0.lowercased()) }) { + return true + } if matches(host: host, path: url.path().lowercased(), blockedImagePrefixes) { return true } diff --git a/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift b/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift index e64ef1e05..da31b5a3a 100644 --- a/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift +++ b/Modules/RSParser/Tests/RSParserTests/HTML/HTMLImageParserTests.swift @@ -66,8 +66,8 @@ import RSParser @Test func imageWithUndeclaredDimensionsIsAccepted() { // Real dimensions are checked at download time. - let html = #""# - #expect(firstSignificantImage(html) == HTMLImage(urlString: "https://example.com/pixel.gif", width: nil, height: nil)) + let html = #""# + #expect(firstSignificantImage(html) == HTMLImage(urlString: "https://example.com/photo.jpg", width: nil, height: nil)) } @Test func gravatarIsSkipped() { @@ -122,6 +122,9 @@ import RSParser #expect(!SignificantImageFilter.isSignificant(urlString: "https://pixel.wp.com/b.gif?v=1", width: nil, height: nil)) #expect(!SignificantImageFilter.isSignificant(urlString: "ftp://example.com/a.jpg", width: nil, height: nil)) #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://example.com/2026/open-source-pixel-art.jpg", width: nil, height: nil)) } }