Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat
as: :html
tests request params as :url_encoded_form
Closes [#50345][] First, handle the exception mentioned in [#50345][]: ``` BugTest#test_params_with_htm_content_type: NoMethodError: undefined method `to_html' for {:name=>"Muad'Dib"}:Hash .../actionpack/lib/action_dispatch/testing/request_encoder.rb:39:in `encode_params' .../actionpack/lib/action_dispatch/testing/integration.rb:251:in `process' ``` When an `ActionDispatch::Testing::RequestEncoder` registered through a call to `register_encoder` does not define a `:param_encoder` keyword argument **and** the params do not respond to a `to_$MIME` method, fallback to returning the `params` themselves, unchanged. This behavior is what's implemented by the private `IdentityEncoder` class, so mimic it for defined encoders. Next, special case handling requests with `as: :html`. Passing `as: :html` implies that the request parameters will come from a `POST` body encoded as `text/html`. That isn't entirely true -- browsers will encode `POST` parameters as with the `Content-Type:` header set to either [application/x-www-form-urlencoded][] or [multipart/form-data][]. This commit skips setting the `CONTENT_TYPE` Rack header when processed with `as: :html`. [#50345]: #50345 [application/x-www-form-urlencoded]: https://developer.mozilla.org/en-US/docs/Learn/Forms/Sending_and_retrieving_form_data#the_post_method [multipart/form-data]: https://developer.mozilla.org/en-US/docs/Learn/Forms/Sending_and_retrieving_form_data#the_enctype_attribute
- Loading branch information