diff --git a/Source/Dictionary+FormURLEncoded.swift b/Source/Dictionary+FormURLEncoded.swift index 60da2db..ed771ce 100644 --- a/Source/Dictionary+FormURLEncoded.swift +++ b/Source/Dictionary+FormURLEncoded.swift @@ -1,3 +1,5 @@ +import Foundation + public extension Dictionary where Key: StringLiteralConvertible { func formURLEncodedFormat() -> String { var converted = "" @@ -8,6 +10,6 @@ public extension Dictionary where Key: StringLiteralConvertible { converted.appendContentsOf("\(entry.0)=\(entry.1)") } - return converted + return converted.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())! } } \ No newline at end of file diff --git a/Tests/Dictionary+FormURLEncodedTests.swift b/Tests/Dictionary+FormURLEncodedTests.swift index 7b8bc68..a0e862d 100644 --- a/Tests/Dictionary+FormURLEncodedTests.swift +++ b/Tests/Dictionary+FormURLEncodedTests.swift @@ -16,9 +16,9 @@ class Dictionary_FormURLEncodedTests: XCTestCase { } func testFormattingOneParameter() { - let parameters = ["password" : "secret"] + let parameters = ["name" : "Elvis Nuñez"] let formatted = parameters.formURLEncodedFormat() - XCTAssertEqual(formatted, "password=secret") + XCTAssertEqual(formatted, "name=Elvis%20Nu%C3%B1ez") } func testFormattingWithEmpty() {