mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-29 08:42:51 +00:00
Reject images with tracking names.
This commit is contained in:
1 parent
308963bd66
commit
377531b40c
2 files changed
+17
-2
No files matched your search
@@ -47,6 +47,12 @@ private extension SignificantImageFilter {
|
||||
|
||||
static let decorativeClasses: Set<String> = ["emoji", "wp-smiley"]
|
||||
|
||||
/// File names, without extension, of tracking pixels and placeholders on any host. Lowercase.
|
||||
static let blockedFileNames: Set<String> = ["1x1", "blank", "pixel", "spacer", "transparent"]
|
||||
|
||||
/// Path components of open-tracking and click-tracking URLs on any host. Lowercase.
|
||||
static let blockedPathComponents: Set<String> = ["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
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ import RSParser
|
||||
|
||||
@Test func imageWithUndeclaredDimensionsIsAccepted() {
|
||||
// Real dimensions are checked at download time.
|
||||
let html = #"<img src="https://example.com/pixel.gif">"#
|
||||
#expect(firstSignificantImage(html) == HTMLImage(urlString: "https://example.com/pixel.gif", width: nil, height: nil))
|
||||
let html = #"<img src="https://example.com/photo.jpg">"#
|
||||
#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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user