Skip to content

Commit

Permalink
fix(ios): Avoid double encoding on http urls (#6288)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Feb 10, 2023
1 parent a7e374f commit 4768085
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class HttpRequestHandler {
}

public static func request(_ call: CAPPluginCall, _ httpMethod: String?, _ config: InstanceConfiguration?) throws {
guard let urlString = call.getString("url")?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { throw URLError(.badURL) }
guard var urlString = call.getString("url") else { throw URLError(.badURL) }
let method = httpMethod ?? call.getString("method", "GET")

// swiftlint:disable force_cast
Expand All @@ -151,6 +151,11 @@ class HttpRequestHandler {
let connectTimeout = call.getDouble("connectTimeout")
let readTimeout = call.getDouble("readTimeout")

if urlString == urlString.removingPercentEncoding {
guard let encodedUrlString = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { throw URLError(.badURL) }
urlString = encodedUrlString
}

let request = try CapacitorHttpRequestBuilder()
.setUrl(urlString)
.setMethod(method)
Expand Down

0 comments on commit 4768085

Please sign in to comment.