mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 09:50:16 +00:00
Add Reddit to SpecialCases. Add tests.
This commit is contained in:
1 parent
3f1fb52580
commit
e3aed79d1d
2 files changed
+31
No files matched your search
@@ -14,6 +14,7 @@ nonisolated public struct SpecialCase {
|
||||
public static let rachelByTheBayHostName = "rachelbythebay.com"
|
||||
public static let openRSSOrgHostName = "openrss.org"
|
||||
public static let youtubeHostName = "youtube.com"
|
||||
public static let redditHostName = "reddit.com"
|
||||
|
||||
public static func urlStringContainSpecialCase(_ urlString: String, _ specialCases: [String]) -> Bool {
|
||||
let lowerURLString = urlString.lowercased(with: localeForLowercasing)
|
||||
@@ -79,6 +80,10 @@ nonisolated extension URL {
|
||||
}
|
||||
return SpecialCase.urlStringContainSpecialCase(host, [SpecialCase.youtubeHostName])
|
||||
}
|
||||
|
||||
public var isRedditURL: Bool {
|
||||
SpecialCase.urlStringMatchesDomain(absoluteString, [SpecialCase.redditHostName])
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated extension Set where Element == URL {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// SpecialCasesTests.swift
|
||||
// RSWebTests
|
||||
//
|
||||
// Created by Brent Simmons on 6/27/26.
|
||||
//
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
@testable import RSWeb
|
||||
|
||||
struct SpecialCasesTests {
|
||||
|
||||
@Test func isRedditURLMatchesSubdomains() {
|
||||
#expect(URL(string: "https://www.reddit.com/r/swift/.rss")!.isRedditURL)
|
||||
#expect(URL(string: "https://old.reddit.com/r/swift/.rss")!.isRedditURL)
|
||||
#expect(URL(string: "https://np.reddit.com/r/swift/.rss")!.isRedditURL)
|
||||
#expect(URL(string: "https://reddit.com/r/swift/.rss")!.isRedditURL)
|
||||
}
|
||||
|
||||
@Test func isRedditURLRejectsLookalikes() {
|
||||
#expect(!URL(string: "https://notreddit.com/feed")!.isRedditURL)
|
||||
#expect(!URL(string: "https://reddit.com.evil.example/feed")!.isRedditURL)
|
||||
#expect(!URL(string: "https://example.com/r/reddit.com")!.isRedditURL)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user