Fix double encoding of path parameters (#15)

Fix double encoding of path parameters

### Motivation

Fixes https://github.com/apple/swift-openapi-generator/issues/251.

### Modifications

Use the already escaped path setter on `URLComponents` to avoid the second encoding pass.

### Result

Path parameters that needed escaping are only escaped once, not twice.

### Test Plan

Adapted the existing unit test to cover a path item that needs escaping.


Reviewed by: simonjbeaumont

Builds:
     ✔︎ pull request validation (5.8) - Build finished. 
     ✔︎ pull request validation (5.9) - Build finished. 
     ✔︎ pull request validation (nightly) - Build finished. 
     ✔︎ pull request validation (soundness) - Build finished. 

https://github.com/swift-server/swift-openapi-async-http-client/pull/15
This commit is contained in:
Honza Dvorsky
2023-09-07 14:53:14 +02:00
committed by GitHub
parent 902cfc7420
commit 7e40bff52d
2 changed files with 3 additions and 3 deletions
@@ -161,7 +161,7 @@ public struct AsyncHTTPClientTransport: ClientTransport {
guard var baseUrlComponents = URLComponents(string: baseURL.absoluteString) else {
throw Error.invalidRequestURL(request: request, baseURL: baseURL)
}
baseUrlComponents.path += request.path
baseUrlComponents.percentEncodedPath += request.path
baseUrlComponents.percentEncodedQuery = request.query
guard let url = baseUrlComponents.url else {
throw Error.invalidRequestURL(request: request, baseURL: baseURL)