Skip to content

Commit

Permalink
fix: Encoding plus symbol in URI's (#191)
Browse files Browse the repository at this point in the history
* fix: Encoding plus symbol in URI's

* add changelog
  • Loading branch information
cbaker6 authored Dec 26, 2024
1 parent 0d51e70 commit 278d971
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
# Parse-Swift Changelog

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

### 5.11.4
[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)

__Fixes__
* 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).
* Encode Firebase notification keys correctly ([#187](https://github.com/netreconlab/Parse-Swift/pull/187)), thanks to [Corey Baker](https://github.com/cbaker6).

### 5.11.3
[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)

Expand Down
5 changes: 5 additions & 0 deletions Sources/ParseSwift/API/API+Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ internal extension API {
return
}
components.queryItems = params
components.percentEncodedQuery = components.percentEncodedQuery?
.replacingOccurrences(
of: "+",
with: "%2B"
)

guard let urlComponents = components.url else {
let error = ParseError(code: .otherCause,
Expand Down
5 changes: 5 additions & 0 deletions Sources/ParseSwift/API/API+NonParseBodyCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ internal extension API {
message: "Could not unwrap url components for \(url)"))
}
components.queryItems = params
components.percentEncodedQuery = components.percentEncodedQuery?
.replacingOccurrences(
of: "+",
with: "%2B"
)

guard let urlComponents = components.url else {
return .failure(ParseError(code: .otherCause,
Expand Down
5 changes: 5 additions & 0 deletions Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ Not attempting to open ParseLiveQuery socket anymore
throw error
}
components.scheme = (components.scheme == "https" || components.scheme == "wss") ? "wss" : "ws"
components.percentEncodedQuery = components.percentEncodedQuery?
.replacingOccurrences(
of: "+",
with: "%2B"
)
url = components.url
self.task = await URLSession.liveQuery.createTask(self.url,
taskDelegate: self)
Expand Down
49 changes: 49 additions & 0 deletions Tests/ParseSwiftTests/APICommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,55 @@ class APICommandTests: XCTestCase {
}
}

func testQueryWhereEncoding() async throws {
let query = Level.query("name" == "test@parse.com")
let parameters = try query.getQueryParameters()

let queryCommand = API.NonParseBodyCommand<Query<Level>, Level?>(
method: .GET,
path: query.endpoint,
params: parameters
) { _ in
return nil
}

switch await queryCommand.prepareURLRequest(options: []) {

case .success(let request):
XCTAssertEqual(
request.url?.absoluteString,
"http://localhost:1337/parse/classes/Level?limit=100&skip=0&where=%7B%22name%22:%22test@parse.com%22%7D"
)
case .failure(let error):
XCTFail(error.localizedDescription)
}
}

func testQueryWhereEncodingPlus() async throws {
let query = Level.query("name" == "test+1@parse.com")
let parameters = try query.getQueryParameters()

let queryCommand = API.NonParseBodyCommand<Query<Level>, Level?>(
method: .GET,
path: query.endpoint,
params: parameters
) { _ in
return nil
}

switch await queryCommand.prepareURLRequest(options: []) {

case .success(let request):
XCTAssertEqual(
request.url?.absoluteString,
// swiftlint:disable:next line_length
"http://localhost:1337/parse/classes/Level?limit=100&skip=0&where=%7B%22name%22:%22test%2B1@parse.com%22%7D"
)
case .failure(let error):
XCTFail(error.localizedDescription)
}
}

func testClientKeyHeader() async throws {
guard let clientKey = ParseSwift.configuration.clientKey else {
throw ParseError(code: .otherCause, message: "Parse configuration should contain key")
Expand Down

0 comments on commit 278d971

Please sign in to comment.