diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-04-26 19:32:49 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-04-26 19:45:55 -0700 |
commit | e06f68fdb2132623d27a26ae58213b09ecb308ee (patch) | |
tree | 17231cded4b5ec956b73fce744b5771cf28c26af /railties/test | |
parent | f52cdaac6336f99d13622ff9bda556a3124a4121 (diff) | |
download | rails-e06f68fdb2132623d27a26ae58213b09ecb308ee.tar.gz rails-e06f68fdb2132623d27a26ae58213b09ecb308ee.tar.bz2 rails-e06f68fdb2132623d27a26ae58213b09ecb308ee.zip |
Do not try to encoding the parameters when the controller is not defined
When you have a route that points to an nonexistent controller we raise
an exception.
This exception was being caught by the DebugExceptions middleware in
development, but when trying to render the error page, we are reading
the request format[[1][]]. To determine the request format we are reading
the format parameters[[2][]], and to be able to read the parameters we need
to encode them[[3][]]. This was raising another exception that to encode the
parameter we try to load the controller to determine if we need to
encode the parameters are binary[[4][]]. This new exception inside the
DebugExceptions middleware makes Rails to render a generic error page.
To avoid this new exception now we only encode the parameters when the
controller can be loaded.
Fixes #28892
[1]: https://github.com/rails/rails/blob/f52cdaac6336f99d13622ff9bda556a3124a4121/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb#L80
[2]: https://github.com/rails/rails/blob/f52cdaac6336f99d13622ff9bda556a3124a4121/actionpack/lib/action_dispatch/http/mime_negotiation.rb#L63
[3]: https://github.com/rails/rails/blob/f52cdaac6336f99d13622ff9bda556a3124a4121/actionpack/lib/action_dispatch/http/parameters.rb#L58
[4]: https://github.com/rails/rails/blob/f52cdaac6336f99d13622ff9bda556a3124a4121/actionpack/lib/action_dispatch/http/parameters.rb#L88
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/middleware/exceptions_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index cbb990f13b..fe07ad3cbe 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -100,6 +100,20 @@ module ApplicationTests end end + test "routing to an nonexistent controller when action_dispatch.show_exceptions and consider_all_requests_local are set shows diagnostics" do + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + resources :articles + end + RUBY + + app.config.action_dispatch.show_exceptions = true + app.config.consider_all_requests_local = true + + get "/articles" + assert_match "<title>Action Controller: Exception caught</title>", last_response.body + end + test "displays diagnostics message when exception raised in template that contains UTF-8" do controller :foo, <<-RUBY class FooController < ActionController::Base |