Skip to content

Commit

Permalink
Merge pull request #46 from 3lvis/improve/formatting-with-escaping
Browse files Browse the repository at this point in the history
Add percent encoding
  • Loading branch information
3lvis committed Dec 23, 2015
2 parents 50a42b2 + ba94ed7 commit 8c30585
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Source/Dictionary+FormURLEncoded.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

public extension Dictionary where Key: StringLiteralConvertible {
func formURLEncodedFormat() -> String {
var converted = ""
Expand All @@ -8,6 +10,6 @@ public extension Dictionary where Key: StringLiteralConvertible {
converted.appendContentsOf("\(entry.0)=\(entry.1)")
}

return converted
return converted.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
}
}
4 changes: 2 additions & 2 deletions Tests/Dictionary+FormURLEncodedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8c30585

Please sign in to comment.