Skip to content

Commit

Permalink
only validate controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed May 29, 2014
1 parent 75bfe64 commit d311922
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -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!
Expand Down Expand Up @@ -237,35 +241,33 @@ 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,
@scope[:module]
)

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."
Expand All @@ -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/

Expand Down

0 comments on commit d311922

Please sign in to comment.