mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 09:50:16 +00:00
Update Feed Finder’s detection of non-feeds to handle uppercase extensions and URL queries and anchors after the extension.
This commit is contained in:
1 parent
4baf1f1132
commit
e2afa2ae25
2 files changed
+26
-8
No files matched your search
@@ -74,19 +74,15 @@ private extension HTMLFeedFinder {
|
||||
}
|
||||
|
||||
static let nonFeedDomains = ["x.com", "twitter.com", "facebook.com", "instagram.com"]
|
||||
static let nonFeedExtensions = ["html", "pdf", "jpg", "jpeg", "png", "gif", "tiff", "heic", "svg", "webp", "bmp", "ico", "zip", "tar", "tgz", "gz", "dmg", "mp3", "mp4", "mov", "mpeg", "mpg", "m4a", "aac", "wav", "aiff", "doc", "docx", "xls", "xlsx", "ppt", "pptx"]
|
||||
static let nonFeedExtensions: Set<String> = ["html", "pdf", "jpg", "jpeg", "png", "gif", "tiff", "heic", "svg", "webp", "bmp", "ico", "zip", "tar", "tgz", "gz", "dmg", "mp3", "mp4", "mov", "mpeg", "mpg", "m4a", "aac", "wav", "aiff", "doc", "docx", "xls", "xlsx", "ppt", "pptx"]
|
||||
|
||||
func urlStringIsDefinitelyNotFeed(_ urlString: String) -> Bool {
|
||||
if SpecialCase.urlStringMatchesDomain(urlString, Self.nonFeedDomains) {
|
||||
return true
|
||||
}
|
||||
for oneExtension in Self.nonFeedExtensions {
|
||||
let fileExtension = ".\(oneExtension)"
|
||||
if urlString.hasSuffix(fileExtension) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
// The path’s extension, so a query or fragment doesn’t hide it.
|
||||
let pathExtension = URL(string: urlString)?.pathExtension ?? (urlString as NSString).pathExtension
|
||||
return Self.nonFeedExtensions.contains(pathExtension.lowercased())
|
||||
}
|
||||
|
||||
func linkMightBeFeed(_ link: HTMLLink) -> Bool {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
import XCTest
|
||||
@testable import FeedFinder
|
||||
import RSParser
|
||||
|
||||
final class FeedFinderTests: XCTestCase {
|
||||
|
||||
@@ -24,4 +25,25 @@ final class FeedFinderTests: XCTestCase {
|
||||
func testKnownFeedSpecifierIgnoresRelayFMRoot() throws {
|
||||
XCTAssertNil(FeedSpecifier.knownFeedSpecifier(url: URL(string: "https://www.relay.fm")!))
|
||||
}
|
||||
|
||||
func testBodyLinksWithNonFeedExtensionsAreIgnored() throws {
|
||||
let urlStrings = feedURLStringsInBodyLinks([
|
||||
"https://example.com/feed.xml",
|
||||
"https://example.com/feed.PDF",
|
||||
"https://example.com/feed.pdf?download=1",
|
||||
"https://example.com/rss.jpg#top"
|
||||
])
|
||||
XCTAssertEqual(urlStrings, ["https://example.com/feed.xml"])
|
||||
}
|
||||
}
|
||||
|
||||
private extension FeedFinderTests {
|
||||
|
||||
func feedURLStringsInBodyLinks(_ urlStrings: [String]) -> Set<String> {
|
||||
let links = urlStrings.map { "<a href=\"\($0)\">Link</a>" }.joined()
|
||||
let html = "<html><body>\(links)</body></html>"
|
||||
let parserData = ParserData(url: "https://example.com/", data: Data(html.utf8))
|
||||
let feedFinder = HTMLFeedFinder(parserData: parserData)
|
||||
return Set(feedFinder.feedSpecifiers.map(\.urlString))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user