Skip to content

Commit 3476848

Browse files
Do not double encode url query parameters. URLQuery class already does this.
1 parent c0115a0 commit 3476848

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

Tests/swift-sdk-swift-tests/IterableRequestUtilTests.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ class IterableRequestUtilTests: XCTestCase {
5757
TestUtils.validate(request: request, requestType: .get, apiEndPoint: apiEndPoint, path: path, queryParams: queryParams)
5858
}
5959

60+
func testGetRequestWithPlusSignInEmail() {
61+
let apiEndPoint = "https://somewhere.com/"
62+
let path = "path"
63+
let args = ["email" : "[email protected]"]
64+
let request = IterableRequestUtil.createGetRequest(forApiEndPoint: apiEndPoint, path: path, args: args)!
65+
let requestString = String(describing: request)
66+
XCTAssertEqual(requestString, "https://somewhere.com/path?email=user%[email protected]")
67+
}
68+
6069
func testPostRequest() {
6170
let apiEndPoint = "https://somewhere.com/"
6271
let path = "path"
@@ -77,11 +86,4 @@ class IterableRequestUtilTests: XCTestCase {
7786
TestUtils.validateElementPresent(withName: "var1", andValue: "val1", inDictionary: bodyFromRequest)
7887
TestUtils.validateElementPresent(withName: "var2", andValue: "val2", inDictionary: bodyFromRequest)
7988
}
80-
81-
func testEncodeUrlQueryParam() {
82-
let encoded = IterableRequestUtil.encodeURLParam("[email protected]")
83-
XCTAssertEqual(encoded!, "you%[email protected]")
84-
XCTAssertEqual(IterableRequestUtil.encodeURLParam(""), "")
85-
XCTAssertNil(IterableRequestUtil.encodeURLParam(nil))
86-
}
8789
}

swift-sdk/Internal/IterableRequestUtil.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,13 @@ struct IterableRequestUtil {
4545
}
4646

4747
if let args = args {
48-
components.queryItems = args.map{ URLQueryItem(name: $0.key, value: encodeURLParam($0.value)) }
48+
components.queryItems = args.map { URLQueryItem(name: $0.key, value: $0.value) }
4949
}
50+
components.percentEncodedQuery = components.percentEncodedQuery?.replacingOccurrences(of: "+", with: "%2B")
5051

5152
return components
5253
}
5354

54-
static func encodeURLParam(_ paramValue: String?) -> String? {
55-
guard let paramValue = paramValue else {
56-
return nil
57-
}
58-
return paramValue.addingPercentEncoding(withAllowedCharacters: encodedCharacterSet)
59-
}
60-
6155
static func dictToJsonData(_ dict: [AnyHashable : Any]?) -> Data? {
6256
guard let dict = dict else {
6357
return nil
@@ -81,10 +75,4 @@ struct IterableRequestUtil {
8175
result.append(path2)
8276
return result
8377
}
84-
85-
private static let encodedCharacterSet : CharacterSet = {
86-
var characterSet = CharacterSet.urlQueryAllowed
87-
characterSet.remove(charactersIn: "+")
88-
return characterSet
89-
} ()
9078
}

0 commit comments

Comments
 (0)