Skip to content

Commit

Permalink
fix: remove key escaping.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew54068 committed Nov 25, 2022
1 parent d0c4642 commit 28ccd42
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
10 changes: 8 additions & 2 deletions Example/Tests/Methods/URLSessionMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ class URLSessionMock: URLSessionProtocol {
with request: URLRequest,
completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void
) -> URLSessionDataTask {
guard let url = request.url else {
return URLSessionDataTaskMock {
completionHandler(nil, nil, nil)
}
}
let error = error
let response = HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: nil)
if let dataString = responseJsonString {
return URLSessionDataTaskMock {
completionHandler(Data(dataString.utf8), nil, error)
completionHandler(Data(dataString.utf8), response, error)
}
}
return URLSessionDataTaskMock {
completionHandler(nil, nil, error)
completionHandler(nil, response, error)
}
}

Expand Down
12 changes: 6 additions & 6 deletions Example/Tests/QueryItemCoding/QueryItemEncodingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
func testDictionaryDecoding() throws {
// Given:
let param = [
QueryName.publicKeySignaturePairs.rawValue + "%5Btest1%5D": "1",
QueryName.publicKeySignaturePairs.rawValue + "%5Btest2%5D": "2"
QueryName.publicKeySignaturePairs.rawValue + "[test1]": "1",
QueryName.publicKeySignaturePairs.rawValue + "[test2]": "2"
]

let expect: [String: String] = [
Expand Down Expand Up @@ -64,8 +64,8 @@
"test2": data2
])
let expect: [URLQueryItem] = [
URLQueryItem(name: QueryName.appendTx.rawValue + "%5Btest1%5D", value: "0x1234"),
URLQueryItem(name: QueryName.appendTx.rawValue + "%5Btest2%5D", value: "0x2345")
URLQueryItem(name: QueryName.appendTx.rawValue + "[test1]", value: "0x1234"),
URLQueryItem(name: QueryName.appendTx.rawValue + "[test2]", value: "0x2345")
]

// When:
Expand All @@ -78,8 +78,8 @@
func testDictionaryDataDecoding() throws {
// Given:
let param = [
QueryName.appendTx.rawValue + "%5Btest1%5D": "1234",
QueryName.appendTx.rawValue + "%5Btest2%5D": "2345"
QueryName.appendTx.rawValue + "[test1]": "1234",
QueryName.appendTx.rawValue + "[test2]": "2345"
]

let expect: [String: Data] = [
Expand Down
10 changes: 5 additions & 5 deletions Sources/Core/Utilities/URLEncoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ public enum URLEncoding {
let boolEncoding = BoolEncoding()
components.append(
.init(
name: escape(key),
name: key,
value: escape(boolEncoding.encode(value: number.boolValue))
))
} else {
components.append(
.init(
name: escape(key),
name: key,
value: escape("\(number)")
))
}
case let bool as Bool:
let boolEncoding = BoolEncoding()
components.append(
.init(
name: escape(key),
name: key,
value: escape(boolEncoding.encode(value: bool))
))
case let data as Data:
components.append(
.init(
name: escape(key),
name: key,
value: data.bloctoSDK.hexStringWith0xPrefix
))
case let string as String:
Expand All @@ -75,7 +75,7 @@ public enum URLEncoding {
default:
components.append(
.init(
name: escape(key),
name: key,
value: "\(value)"
))
}
Expand Down

0 comments on commit 28ccd42

Please sign in to comment.