Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

only validate controllers

  • Loading branch information...
commit d311922c82ace9de7ca588b47a54716835bdca2a 1 parent 75bfe64
@tenderlove tenderlove authored
Showing with 17 additions and 15 deletions.
  1. +17 −15 actionpack/lib/action_dispatch/routing/mapper.rb
View
32 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -127,7 +127,11 @@ def normalize_options!(options)
options[:controller] ||= /.+?/
end
- options.merge!(default_controller_and_action)
+ if to.respond_to? :call
+ options
+ else
+ options.merge!(default_controller_and_action)
+ end
end
def normalize_requirements!
@@ -237,8 +241,6 @@ def app
end
def default_controller_and_action
- return {} if to.respond_to? :call
-
controller, action = get_controller_and_action(default_controller,
default_action,
to,
@@ -246,26 +248,26 @@ def default_controller_and_action
)
hash = check_part(:controller, controller, {}) do |part|
- if part =~ %r{\A/}
- message = "controller name should not start with a slash"
- else
- message = "'#{part}' is not a supported controller name. This can lead to potential routing problems."
- message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use"
- end
+ translate_controller(part) {
+ if part =~ %r{\A/}
+ message = "controller name should not start with a slash"
+ else
+ message = "'#{part}' is not a supported controller name. This can lead to potential routing problems."
+ message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use"
+ end
- raise ArgumentError, message
+ raise ArgumentError, message
+ }
end
check_part(:action, action, hash) { |part|
- # we never get here in the tests, but I believe this block should
- # be the same as the `controller` block.
- part.to_s
+ part.is_a?(Regexp) ? part : part.to_s
}
end
def check_part(name, part, hash)
if part
- hash[name] = translate_part(name, part) { yield(part) }
+ hash[name] = yield(part)
else
unless segment_keys.include?(name)
message = "Missing :#{name} key on routes definition, please check your routes."
@@ -292,7 +294,7 @@ def get_controller_and_action(controller, action, to, modyoule)
[controller, action]
end
- def translate_part(name, controller)
+ def translate_controller(controller)
return controller if Regexp === controller
return controller.to_s if controller =~ /\A[a-z_0-9][a-z_0-9\/]*\z/
Please sign in to comment.
Something went wrong with that request. Please try again.