diff options
author | Maxime Garcia <maxime.garcia@gmail.com> | 2015-12-12 11:22:08 +0100 |
---|---|---|
committer | Maxime Garcia <maxime.garcia@gmail.com> | 2015-12-12 11:22:08 +0100 |
commit | d3dd3847bc2633ecead36f602bfca21c9362b502 (patch) | |
tree | a3ffb516dc7d435b12f10c5ae40d9252411da6b7 | |
parent | eb0e8e216fcf535a1e6b82720dfb7639fcc20ff2 (diff) | |
download | rails-d3dd3847bc2633ecead36f602bfca21c9362b502.tar.gz rails-d3dd3847bc2633ecead36f602bfca21c9362b502.tar.bz2 rails-d3dd3847bc2633ecead36f602bfca21c9362b502.zip |
Don't catch all NameError to reraise as ActionController::RoutingError #22368
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 6 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 41 |
2 files changed, 45 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index c4228df925..2bd2e53252 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -30,9 +30,9 @@ module ActionDispatch controller = controller req res = controller.make_response! req dispatch(controller, params[:action], req, res) - rescue NameError => e + rescue ActionController::RoutingError if @raise_on_name_error - raise ActionController::RoutingError, e.message, e.backtrace + raise else return [404, {'X-Cascade' => 'pass'}, []] end @@ -42,6 +42,8 @@ module ActionDispatch def controller(req) req.controller_class + rescue NameError => e + raise ActionController::RoutingError, e.message, e.backtrace end def dispatch(controller, action, req, res) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 8972f3e74d..82222a141c 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -4592,3 +4592,44 @@ class TestDefaultUrlOptions < ActionDispatch::IntegrationTest assert_equal '/en/posts/2014/12/13', archived_posts_path(2014, 12, 13) end end + +class TestErrorsInController < ActionDispatch::IntegrationTest + class ::PostsController < ActionController::Base + def foo + nil.i_do_not_exist + end + + def bar + NonExistingClass.new + end + end + + Routes = ActionDispatch::Routing::RouteSet.new + Routes.draw do + get '/:controller(/:action)' + end + + APP = build_app Routes + + def app + APP + end + + def test_legit_no_method_errors_are_not_caught + get '/posts/foo' + assert_equal 500, response.status + end + + def test_legit_name_errors_are_not_caught + get '/posts/bar' + assert_equal 500, response.status + end + + def test_legit_routing_not_found_responses + get '/posts/baz' + assert_equal 404, response.status + + get '/i_do_not_exist' + assert_equal 404, response.status + end +end |