Skip to content

Commit 278d971

Browse files
authored
fix: Encoding plus symbol in URI's (#191)
* fix: Encoding plus symbol in URI's * add changelog
1 parent 0d51e70 commit 278d971

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22
# Parse-Swift Changelog
33

44
### main
5-
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.3...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
5+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.4...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

8+
### 5.11.4
9+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.3...5.11.4), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.11.4/documentation/parseswift)
10+
11+
__Fixes__
12+
* Encode plus symbol in query parameter URI's to server ([#191](https://github.com/netreconlab/Parse-Swift/pull/191)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
* Encode Firebase notification keys correctly ([#187](https://github.com/netreconlab/Parse-Swift/pull/187)), thanks to [Corey Baker](https://github.com/cbaker6).
14+
815
### 5.11.3
916
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.2...5.11.3), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.11.3/documentation/parseswift)
1017

Sources/ParseSwift/API/API+Command.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ internal extension API {
276276
return
277277
}
278278
components.queryItems = params
279+
components.percentEncodedQuery = components.percentEncodedQuery?
280+
.replacingOccurrences(
281+
of: "+",
282+
with: "%2B"
283+
)
279284

280285
guard let urlComponents = components.url else {
281286
let error = ParseError(code: .otherCause,

Sources/ParseSwift/API/API+NonParseBodyCommand.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ internal extension API {
7878
message: "Could not unwrap url components for \(url)"))
7979
}
8080
components.queryItems = params
81+
components.percentEncodedQuery = components.percentEncodedQuery?
82+
.replacingOccurrences(
83+
of: "+",
84+
with: "%2B"
85+
)
8186

8287
guard let urlComponents = components.url else {
8388
return .failure(ParseError(code: .otherCause,

Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ Not attempting to open ParseLiveQuery socket anymore
154154
throw error
155155
}
156156
components.scheme = (components.scheme == "https" || components.scheme == "wss") ? "wss" : "ws"
157+
components.percentEncodedQuery = components.percentEncodedQuery?
158+
.replacingOccurrences(
159+
of: "+",
160+
with: "%2B"
161+
)
157162
url = components.url
158163
self.task = await URLSession.liveQuery.createTask(self.url,
159164
taskDelegate: self)

Tests/ParseSwiftTests/APICommandTests.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,55 @@ class APICommandTests: XCTestCase {
407407
}
408408
}
409409

410+
func testQueryWhereEncoding() async throws {
411+
let query = Level.query("name" == "test@parse.com")
412+
let parameters = try query.getQueryParameters()
413+
414+
let queryCommand = API.NonParseBodyCommand<Query<Level>, Level?>(
415+
method: .GET,
416+
path: query.endpoint,
417+
params: parameters
418+
) { _ in
419+
return nil
420+
}
421+
422+
switch await queryCommand.prepareURLRequest(options: []) {
423+
424+
case .success(let request):
425+
XCTAssertEqual(
426+
request.url?.absoluteString,
427+
"http://localhost:1337/parse/classes/Level?limit=100&skip=0&where=%7B%22name%22:%22test@parse.com%22%7D"
428+
)
429+
case .failure(let error):
430+
XCTFail(error.localizedDescription)
431+
}
432+
}
433+
434+
func testQueryWhereEncodingPlus() async throws {
435+
let query = Level.query("name" == "test+1@parse.com")
436+
let parameters = try query.getQueryParameters()
437+
438+
let queryCommand = API.NonParseBodyCommand<Query<Level>, Level?>(
439+
method: .GET,
440+
path: query.endpoint,
441+
params: parameters
442+
) { _ in
443+
return nil
444+
}
445+
446+
switch await queryCommand.prepareURLRequest(options: []) {
447+
448+
case .success(let request):
449+
XCTAssertEqual(
450+
request.url?.absoluteString,
451+
// swiftlint:disable:next line_length
452+
"http://localhost:1337/parse/classes/Level?limit=100&skip=0&where=%7B%22name%22:%22test%2B1@parse.com%22%7D"
453+
)
454+
case .failure(let error):
455+
XCTFail(error.localizedDescription)
456+
}
457+
}
458+
410459
func testClientKeyHeader() async throws {
411460
guard let clientKey = ParseSwift.configuration.clientKey else {
412461
throw ParseError(code: .otherCause, message: "Parse configuration should contain key")

0 commit comments

Comments
 (0)