From 4768085414768bb2c013afcc6c645664893cd297 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Fri, 10 Feb 2023 10:05:29 +0100 Subject: [PATCH] fix(ios): Avoid double encoding on http urls (#6288) --- ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift b/ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift index 963b16225f..40cef58dc6 100644 --- a/ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift +++ b/ios/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift @@ -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 @@ -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)