Skip to content

Commit ed18f78

Browse files
committed
Set specific encoding only for brose cursor
1 parent 90f5df9 commit ed18f78

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

Sources/AlgoliaSearchClient/Command/Command+Search.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension Command {
4040
}
4141

4242
init(indexName: IndexName, cursor: Cursor? = nil, requestOptions: RequestOptions?) {
43-
self.requestOptions = requestOptions.updateOrCreate(cursor.flatMap { [.cursor: $0.rawValue] } ?? [:])
43+
self.requestOptions = requestOptions.updateOrCreate(cursor.flatMap { [.cursor: $0.rawValue.addingPercentEncoding(withAllowedCharacters: .uriAllowed)] } ?? [:])
4444
let path = .indexesV1 >>> .index(indexName) >>> IndexCompletion.browse
4545
urlRequest = .init(method: .get, path: path, requestOptions: self.requestOptions)
4646
}

Sources/AlgoliaSearchClient/Transport/URLSession/URLRequest+Convenience.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension URLRequest: Builder {}
1111

1212
extension CharacterSet {
1313

14-
static var uriAllowed = CharacterSet.alphanumerics.union(.init(charactersIn: "-_.!~*'()"))
14+
static var uriAllowed = CharacterSet.urlQueryAllowed.subtracting(.init(charactersIn: "+"))
1515

1616
}
1717

@@ -36,15 +36,7 @@ extension URLRequest {
3636
urlComponents.path = path.fullPath
3737

3838
if let urlParameters = requestOptions?.urlParameters {
39-
urlComponents.queryItems = urlParameters
40-
.map { (key, value) in
41-
guard let encodedName = key.rawValue.addingPercentEncoding(withAllowedCharacters: .uriAllowed) else {
42-
return nil
43-
}
44-
let encodedValue = value?.addingPercentEncoding(withAllowedCharacters: .uriAllowed)
45-
return URLQueryItem(name: encodedName, value: encodedValue)
46-
}
47-
.compactMap { $0 }
39+
urlComponents.queryItems = urlParameters.map { (key, value) in .init(name: key.rawValue, value: value) }
4840
}
4941

5042
var request = URLRequest(url: urlComponents.url!)

Tests/AlgoliaSearchClientTests/Unit/Command/SearchCommandTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class SearchCommandTests: XCTestCase, AlgoliaCommandTest {
3939
callType: .read,
4040
method: .get,
4141
urlPath: "/1/indexes/testIndex/browse",
42-
queryItems: [.init(name: "testParameter", value: "testParameterValue"), .init(name: "cursor", value: "AgA%2BBgg4MTUyNTQ0Mg%3D%3D")],
42+
queryItems: [.init(name: "testParameter", value: "testParameterValue"), .init(name: "cursor", value: "AgA%2BBgg4MTUyNTQ0Mg==")],
4343
body: nil,
4444
requestOptions: test.requestOptions)
4545
}

0 commit comments

Comments
 (0)