mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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]:f52cdaac63/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb (L80)
[2]:f52cdaac63/actionpack/lib/action_dispatch/http/mime_negotiation.rb (L63)
[3]:f52cdaac63/actionpack/lib/action_dispatch/http/parameters.rb (L58)
[4]:f52cdaac63/actionpack/lib/action_dispatch/http/parameters.rb (L88)
This commit is contained in:
parent
f52cdaac63
commit
e06f68fdb2
2 changed files with 21 additions and 1 deletions
|
@ -85,7 +85,7 @@ module ActionDispatch
|
|||
|
||||
def set_binary_encoding(params)
|
||||
action = params[:action]
|
||||
if controller_class.binary_params_for?(action)
|
||||
if binary_params_for?(action)
|
||||
ActionDispatch::Request::Utils.each_param_value(params) do |param|
|
||||
param.force_encoding ::Encoding::ASCII_8BIT
|
||||
end
|
||||
|
@ -93,6 +93,12 @@ module ActionDispatch
|
|||
params
|
||||
end
|
||||
|
||||
def binary_params_for?(action)
|
||||
controller_class.binary_params_for?(action)
|
||||
rescue NameError
|
||||
false
|
||||
end
|
||||
|
||||
def parse_formatted_parameters(parsers)
|
||||
return yield if content_length.zero? || content_mime_type.nil?
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue