Handle +’s in the query items

+’s in query items can be treated as spaces by services. We want to encode them properly (via URLComponents.enhancedPercentEncodedQuery)

This private entension might be worth moving into RSWeb.

Fixes #2544
This commit is contained in:
Jonathan Bennett 2020-11-12 03:44:54 -05:00
parent c4cfa5b57e
commit 21c2787f90

View File

@ -111,13 +111,17 @@ final class FeedWranglerAPICaller: NSObject {
}
func renameSubscription(feedID: String, newName: String, completion: @escaping (Result<Void, Error>) -> Void) {
let url = FeedWranglerConfig.clientURL
.appendingPathComponent("subscriptions/rename_feed")
.appendingQueryItems([
URLQueryItem(name: "feed_id", value: feedID),
URLQueryItem(name: "feed_name", value: newName),
])
var postData = URLComponents(url: FeedWranglerConfig.clientURL, resolvingAgainstBaseURL: false)
postData?.path += "subscriptions/rename_feed"
postData?.queryItems = [
URLQueryItem(name: "feed_id", value: feedID),
URLQueryItem(name: "feed_name", value: newName),
]
guard let url = postData?.urlWithEnhancedPercentEncodedQuery else {
fatalError() // something has gone terribly wrong
}
standardSend(url: url, resultType: FeedWranglerSubscriptionsRequest.self) { result in
switch result {
case .success:
@ -290,3 +294,16 @@ final class FeedWranglerAPICaller: NSObject {
}
}
private extension URLComponents {
var urlWithEnhancedPercentEncodedQuery: URL? {
guard let tempQueryItems = self.queryItems, !tempQueryItems.isEmpty else {
return self.url
}
var tempComponents = self
tempComponents.percentEncodedQuery = self.enhancedPercentEncodedQuery
return tempComponents.url
}
}