From faaf280d1277d22c7798a1e62726cc49e1df7ddc Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 8 May 2020 16:13:25 -0500 Subject: [PATCH] Add additional Reddit URL validation --- Frameworks/Account/FeedProvider/FeedProvider.swift | 2 +- .../Account/FeedProvider/Reddit/RedditFeedProvider.swift | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Frameworks/Account/FeedProvider/FeedProvider.swift b/Frameworks/Account/FeedProvider/FeedProvider.swift index 065547372..d11d56e13 100644 --- a/Frameworks/Account/FeedProvider/FeedProvider.swift +++ b/Frameworks/Account/FeedProvider/FeedProvider.swift @@ -29,7 +29,7 @@ public protocol FeedProvider { /// Provide the iconURL of the given URL func iconURL(_ urlComponents: URLComponents, completion: @escaping (Result) -> Void) - /// Construct the associated metadata for the new feed + /// Construct the associated metadata for the new feed. If the URL won't be recognized by this Feed Provider, it will error here. func metaData(_ urlComponents: URLComponents, completion: @escaping (Result) -> Void) /// Refresh all the article entries (ParsedItems) diff --git a/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift b/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift index 07192c38c..e3f683bbb 100644 --- a/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift +++ b/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift @@ -124,11 +124,16 @@ public final class RedditFeedProvider: FeedProvider { return } - guard splitPath.count > 1 else { + guard splitPath.count > 1, splitPath.count < 4, splitPath[0] == "r" else { completion(.failure(RedditFeedProviderError.unknown)) return } + if splitPath.count == 3 && RedditSort(rawValue: String(splitPath[2])) == nil { + completion(.failure(RedditFeedProviderError.unknown)) + return + } + let homePageURL = "https://www.reddit.com/\(splitPath[0])/\(splitPath[1])" subreddit(urlComponents) { result in