-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URLSession and AHC transports double-encode path parameters #251
URLSession and AHC transports double-encode path parameters #251
Comments
Thanks for filing, yes that looks like a bug. |
I tried to reproduce in a unit test, but seems to be behaving correctly: apple/swift-openapi-runtime#49 Possibly this could be caused by the client using 0.2 and server 0.1? I could see that leaving the client as escaped, but not being unescaped on the server. |
found it, it is actually a bug in the URLSessionTransport's initializer of The URLComponents.url adds another round of percent encoding, basically sending an double-encoded path parameter to the server. |
Fix double encoding of path parameters ### Motivation Fixes apple/swift-openapi-generator#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. #15
Fix double encoding of path parameters ### Motivation Fixes apple/swift-openapi-generator#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. #14
Ok both the URLSession and AHC transports have been released with this fix in 0.2.2. Thank you @sliemeobn for doing the heavy lifting on this one! 🙏 |
### Motivation While investigating apple/swift-openapi-generator#251 I noticed we don't have a test case for an escaped path component. ### Modifications Added an extra test case. ### Result Unescaping path params has better test coverage. ### Test Plan This whole PR is about improving the tests.
When using String path parameters, the generated client (correctly) URL-encodes the values to be included in the path.
However, the server handler just passes the the "raw" string value in the
input.path
structure.Eg:
using the generated client:
server code
I would expect this to be symmetric and arrive decoded in the handler.
The text was updated successfully, but these errors were encountered: