mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Raise ArgumentError if route name is invalid [#6517 state:resolved]
This commit is contained in:
parent
0509bf35f1
commit
e00867bc43
2 changed files with 34 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
require 'rack/mount'
|
||||
require 'forwardable'
|
||||
require 'active_support/core_ext/object/blank'
|
||||
require 'active_support/core_ext/object/to_query'
|
||||
require 'active_support/core_ext/hash/slice'
|
||||
|
||||
|
@ -330,6 +331,7 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true)
|
||||
raise ArgumentError, "Invalid route name: '#{name}'" unless name.blank? || name.to_s.match(/^[_a-z]\w*$/i)
|
||||
route = Route.new(self, app, conditions, requirements, defaults, name, anchor)
|
||||
@set.add_route(*route)
|
||||
named_routes[name] = route if name
|
||||
|
|
|
@ -2313,6 +2313,38 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
def test_invalid_route_name_raises_error
|
||||
assert_raise(ArgumentError) do
|
||||
self.class.stub_controllers do |routes|
|
||||
routes.draw { get '/products', :to => 'products#index', :as => 'products ' }
|
||||
end
|
||||
end
|
||||
|
||||
assert_raise(ArgumentError) do
|
||||
self.class.stub_controllers do |routes|
|
||||
routes.draw { get '/products', :to => 'products#index', :as => ' products' }
|
||||
end
|
||||
end
|
||||
|
||||
assert_raise(ArgumentError) do
|
||||
self.class.stub_controllers do |routes|
|
||||
routes.draw { get '/products', :to => 'products#index', :as => 'products!' }
|
||||
end
|
||||
end
|
||||
|
||||
assert_raise(ArgumentError) do
|
||||
self.class.stub_controllers do |routes|
|
||||
routes.draw { get '/products', :to => 'products#index', :as => 'products index' }
|
||||
end
|
||||
end
|
||||
|
||||
assert_raise(ArgumentError) do
|
||||
self.class.stub_controllers do |routes|
|
||||
routes.draw { get '/products', :to => 'products#index', :as => '1products' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_nested_route_in_nested_resource
|
||||
get "/posts/1/comments/2/views"
|
||||
assert_equal "comments#views", @response.body
|
||||
|
|
Loading…
Reference in a new issue