aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/mapper.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-09-05 15:45:06 +0200
committerJosé Valim <jose.valim@gmail.com>2010-09-05 15:45:12 +0200
commit9757bfff9b7fff21697228dd0920d8ea93fae969 (patch)
tree2bc0c9acc5f17cb03b111d9448c2e100979bd0e2 /actionpack/lib/action_dispatch/routing/mapper.rb
parente20012b64b2063b75cbf1acc57195f0c410987de (diff)
parente909afccc996293ec6b7ba2d1c6c078fe807956b (diff)
downloadrails-9757bfff9b7fff21697228dd0920d8ea93fae969.tar.gz
rails-9757bfff9b7fff21697228dd0920d8ea93fae969.tar.bz2
rails-9757bfff9b7fff21697228dd0920d8ea93fae969.zip
Merge remote branch 'drogus/remove_deprecated_routes'
This merge removes the deprecated routes mapper from Rails and update its tests.
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb38
1 files changed, 30 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 900900ee24..fdcfe26781 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -113,6 +113,15 @@ module ActionDispatch
@requirements ||= (@options[:constraints].is_a?(Hash) ? @options[:constraints] : {}).tap do |requirements|
requirements.reverse_merge!(@scope[:constraints]) if @scope[:constraints]
@options.each { |k, v| requirements[k] = v if v.is_a?(Regexp) }
+
+ requirements.each do |_, requirement|
+ if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
+ raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}"
+ end
+ if requirement.multiline?
+ raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}"
+ end
+ end
end
end
@@ -443,11 +452,6 @@ module ActionDispatch
options = args.extract_options!
options = options.dup
- if name_prefix = options.delete(:name_prefix)
- options[:as] ||= name_prefix
- ActiveSupport::Deprecation.warn ":name_prefix was deprecated in the new router syntax. Use :as instead.", caller
- end
-
options[:path] = args.first if args.first.is_a?(String)
recover = {}
@@ -616,9 +620,18 @@ module ActionDispatch
end
def actions
- if only = @options[:only]
+ only, except = @options.values_at(:only, :except)
+ if only == :all || except == :none
+ only = nil
+ except = []
+ elsif only == :none || except == :all
+ only = []
+ except = nil
+ end
+
+ if only
Array(only).map(&:to_sym)
- elsif except = @options[:except]
+ elsif except
default_actions - Array(except).map(&:to_sym)
else
default_actions
@@ -770,7 +783,7 @@ module ActionDispatch
end
resource_scope(Resource.new(resources.pop, options)) do
- yield if block_given?
+ instance_eval(&block) if block_given?
collection_scope do
get :index if parent_resource.actions.include?(:index)
@@ -894,6 +907,15 @@ module ActionDispatch
return self
end
+ via = Array.wrap(options[:via]).map(&:to_sym)
+ if via.include?(:head)
+ raise ArgumentError, "HTTP method HEAD is invalid in route conditions. Rails processes HEAD requests the same as GETs, returning just the response headers"
+ end
+
+ unless (invalid = via - HTTP_METHODS).empty?
+ raise ArgumentError, "Invalid HTTP method (#{invalid.join(', ')}) specified in :via"
+ end
+
on = options.delete(:on)
if VALID_ON_OPTIONS.include?(on)
args.push(options)