You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example) -> silver sponsor
Description
HTTP body for application/x-www-form-urlencoded requests does not get percent encoded using URLSession template. We detected this when migrating from Alamofire to URLSession template, in Alamofire this worked as described below
Since the code is the same I guess the same issue should happen with swift5
Steps to reproduce
Use the minimal spec with the provided config. The HTTP body of the request sent will be similar to: client_id=7cfaf41e-aa18-40fd-a871-a21140d8e403&grant_type=password&password=foobarbaz&scope=openid email phone profile offline_access some-uid&username=+511287237674
Note that the spaces between the scopes and the + sign in the username are not percent encoded.
Expected output should be similar to: client_id=7cfaf41e-aa18-40fd-a871-a21140d8e403&grant_type=password&password=foobarbaz&scope=phone%20some-uid%20openid%20profile%20email%20offline_access&username=%2B511287237674
Suggest a fix
The problem is that in private class FormURLEncoding -> func encode adds the non-escaped query to the httpBody: urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
This means that any percent encoding needs to be done manually for the parameters. Changing this to urlRequest.httpBody = requestBodyComponents.percentEncodedQuery?.data(using: .utf8) does not solve the issue entirely since the + sign will not be percent encoded.
I suggest to fix this by manually percent encoding each query item using .addingPercentEncoding(withAllowedCharacters: .alphanumerics) before adding them to requestBodyComponents.queryItems
If this is accepted as a bug I could contribute a fix for it.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
HTTP body for application/x-www-form-urlencoded requests does not get percent encoded using URLSession template. We detected this when migrating from Alamofire to URLSession template, in Alamofire this worked as described below
openapi-generator version
7.10.0
OpenAPI declaration file content or url
Generation Details
config:
Since the code is the same I guess the same issue should happen with swift5
Steps to reproduce
Use the minimal spec with the provided config. The HTTP body of the request sent will be similar to:
client_id=7cfaf41e-aa18-40fd-a871-a21140d8e403&grant_type=password&password=foobarbaz&scope=openid email phone profile offline_access some-uid&username=+511287237674
Note that the spaces between the scopes and the
+
sign in the username are not percent encoded.Expected output should be similar to:
client_id=7cfaf41e-aa18-40fd-a871-a21140d8e403&grant_type=password&password=foobarbaz&scope=phone%20some-uid%20openid%20profile%20email%20offline_access&username=%2B511287237674
Suggest a fix
The problem is that in
private class FormURLEncoding
->func encode
adds the non-escaped query to the httpBody:urlRequest.httpBody = requestBodyComponents.query?.data(using: .utf8)
This means that any percent encoding needs to be done manually for the parameters. Changing this to
urlRequest.httpBody = requestBodyComponents.percentEncodedQuery?.data(using: .utf8)
does not solve the issue entirely since the+
sign will not be percent encoded.I suggest to fix this by manually percent encoding each query item using
.addingPercentEncoding(withAllowedCharacters: .alphanumerics)
before adding them torequestBodyComponents.queryItems
If this is accepted as a bug I could contribute a fix for it.
The text was updated successfully, but these errors were encountered: