From 60aa6eca3604bd6f1fd511cf722bff0dd572ae1e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 14 Sep 2019 15:32:20 -0400 Subject: [PATCH] Fix pagination links not being parsed correctly for some URLs Fixes an issue where Mentions notifications wouldn't load past the first page. URLComponents(string:) fails when the string contains some characters, such as [ or ] URL(string:) and then URLComponents(url:resolvingAgainstBaseURL:) does not fail See FB7271340 --- Pachyderm/Response/Pagination.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Pachyderm/Response/Pagination.swift b/Pachyderm/Response/Pagination.swift index a80bb3c8..2683911b 100644 --- a/Pachyderm/Response/Pagination.swift +++ b/Pachyderm/Response/Pagination.swift @@ -44,13 +44,16 @@ extension Pagination { } let rel = segments.last?.replacingOccurrences(of: "\"", with: "").trimmingCharacters(in: .whitespaces).components(separatedBy: "=") - guard let validURL = url, + guard let urlStr = url, + let validURL = URL(string: urlStr), let key = rel?.first, key == "rel", let value = rel?.last, let kind = Kind(rawValue: value), - let components = URLComponents(string: validURL), - let queryItems = components.queryItems else { return nil } + let components = URLComponents(url: validURL, resolvingAgainstBaseURL: false), + let queryItems = components.queryItems else { + return nil + } let min = queryItems.first { $0.name == "min_id" }?.value let since = queryItems.first { $0.name == "since_id" }?.value