Remove explicit URL encoding of query params

This commit is contained in:
Daniel Saidi 2021-05-04 08:58:40 +02:00
parent 4969f38b19
commit 41c3a2afc3
4 changed files with 16 additions and 6 deletions

View File

@ -3,6 +3,12 @@
Until 1.0, breaking changes can occur in minor versions.
## 0.6.1
This version removes the explicit url encoding of `ApiRoute` query params, since the new query builder does this.
## 0.6.0
### ✨ New features

View File

@ -82,7 +82,7 @@ public extension ApiRoute {
*/
var queryItems: [URLQueryItem] {
queryParams
.map { URLQueryItem(name: $0.key, value: paramValue(for: $0.value)) }
.map { URLQueryItem(name: $0.key, value: $0.value) }
.sorted { $0.name < $1.name }
}

View File

@ -28,6 +28,10 @@ class String_UrlEncodeTests: QuickSpec {
expect("foo=bar&baz=123".urlEncoded()).to(equal("foo=bar%26baz=123"))
}
it("handles square brackets") {
expect("foo=[bar]".urlEncoded()).to(equal("foo=%5Bbar%5D"))
}
it("handles swedish chars") {
expect("åäöÅÄÖ".urlEncoded()).to(equal("%C3%A5%C3%A4%C3%B6%C3%85%C3%84%C3%96"))
}

View File

@ -31,7 +31,7 @@ class ApiRouteTests: QuickSpec {
it("is correctly configured") {
let req = route.formDataRequest(for: env)
let expectedData = "baz?=BAM%3F&foo&=bar%26".data(using: .utf8)
expect(req.url?.absoluteString).to(equal("http://example.com/1/2/3?anyone?=there%253F&hello%26=world%2526"))
expect(req.url?.absoluteString).to(equal("http://example.com/1/2/3?anyone?=there?&hello%26=world%26"))
expect(req.allHTTPHeaderFields?["Content-Type"]).to(equal("application/x-www-form-urlencoded"))
expect(req.httpBody).to(equal(expectedData))
}
@ -39,13 +39,13 @@ class ApiRouteTests: QuickSpec {
describe("query items") {
it("are mapped query params") {
it("are mapped query params without url encoding") {
let items = route.queryItems.sorted { $0.name < $1.name }
expect(items.count).to(equal(2))
expect(items[0].name).to(equal("anyone?"))
expect(items[0].value).to(equal("there%3F"))
expect(items[0].value).to(equal("there?"))
expect(items[1].name).to(equal("hello&"))
expect(items[1].value).to(equal("world%26"))
expect(items[1].value).to(equal("world&"))
}
}
@ -53,7 +53,7 @@ class ApiRouteTests: QuickSpec {
it("is correctly configured") {
let req = route.request(for: env)
expect(req.url?.absoluteString).to(equal("http://example.com/1/2/3?anyone?=there%253F&hello%26=world%2526"))
expect(req.url?.absoluteString).to(equal("http://example.com/1/2/3?anyone?=there?&hello%26=world%26"))
expect(req.allHTTPHeaderFields?["Content-Type"]).to(equal("application/json"))
}
}