Browse Source

Escape quotes in curl command

JSON will have quotes which need to be escaped before being run on the
command line.
John Gibb 11 years ago
parent
commit
0193659cc7
1 changed files with 3 additions and 1 deletions
  1. 3 1
      Source/Alamofire.swift

+ 3 - 1
Source/Alamofire.swift

@@ -1261,7 +1261,9 @@ extension Request: DebugPrintable {
         }
         
         if let HTTPBody = request.HTTPBody {
-            components.append("-d \"\(NSString(data: HTTPBody, encoding: NSUTF8StringEncoding))\"")
+            let escapedBody = NSString(data: HTTPBody, encoding: NSUTF8StringEncoding)
+                                .stringByReplacingOccurrencesOfString("\"", withString: "\\\"")
+            components.append("-d \"\(escapedBody)\"")
         }
 
         components.append("\"\(URL.absoluteString!)\"")