From 9fd0c605b9bcfb2c2e854f3120bd3625eaa017f5 Mon Sep 17 00:00:00 2001 From: Xavier Defrang Date: Fri, 28 Jun 2013 15:37:26 +0200 Subject: Verify that route constraints respond to the expected messages instead of silently failing to enforce the constraint --- actionpack/lib/action_dispatch/routing/mapper.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 288ce3e867..ff33d87901 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -156,6 +156,8 @@ module ActionDispatch next unless URL_OPTIONS.include?(key) && (String === default || Fixnum === default) @defaults[key] ||= default end + elsif options[:constraints] + verify_callable_constraint(options[:constraints]) end if Regexp === options[:format] @@ -165,6 +167,11 @@ module ActionDispatch end end + def verify_callable_constraint(callable_constraint) + return if callable_constraint.respond_to?(:call) || callable_constraint.respond_to?(:matches?) + raise ArgumentError, "Invalid constraint: #{callable_constraint.inspect} must respond to :call or :matches?" + end + def normalize_conditions! @conditions.merge!(:path_info => path) -- cgit v1.2.3