Skip to content

Commit

Permalink
fix(ios): encode whitespace in http plugin urls (#6169)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Dec 16, 2022
1 parent f4e7f19 commit dccb0a9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
4 changes: 0 additions & 4 deletions ios/Capacitor/Capacitor/Plugins/CapacitorHttp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import Foundation
@objc(CAPHttpPlugin)
public class CAPHttpPlugin: CAPPlugin {
@objc func http(_ call: CAPPluginCall, _ httpMethod: String?) {
// Protect against bad values from JS before calling request
guard let url = call.getString("url") else { return call.reject("Must provide a URL"); }
guard var _ = URL(string: url) else { return call.reject("Invalid URL"); }

do {
try HttpRequestHandler.request(call, httpMethod, self.bridge?.config)
} catch let error {
Expand Down
2 changes: 1 addition & 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") else { throw URLError(.badURL) }
guard let urlString = call.getString("url")?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { throw URLError(.badURL) }
let method = httpMethod ?? call.getString("method", "GET")

// swiftlint:disable force_cast
Expand Down

0 comments on commit dccb0a9

Please sign in to comment.