aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorXavier Defrang <xavier.defrang@gmail.com>2013-06-28 15:37:26 +0200
committerXavier Defrang <xavier.defrang@gmail.com>2013-06-28 15:54:48 +0200
commit9fd0c605b9bcfb2c2e854f3120bd3625eaa017f5 (patch)
tree3c8daeba169acbb5da53caafb0b1e5ba93e97522 /actionpack/lib/action_dispatch
parent55193e449a377c448e43d8fec42899ea1ff93b27 (diff)
downloadrails-9fd0c605b9bcfb2c2e854f3120bd3625eaa017f5.tar.gz
rails-9fd0c605b9bcfb2c2e854f3120bd3625eaa017f5.tar.bz2
rails-9fd0c605b9bcfb2c2e854f3120bd3625eaa017f5.zip
Verify that route constraints respond to the expected messages instead of silently failing to enforce the constraint
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb7
1 files changed, 7 insertions, 0 deletions
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)