Skip to content

Commit

Permalink
raise error on invalid HTTP methods or :head passed with :via in routes
Browse files Browse the repository at this point in the history
  • Loading branch information
drogus committed Sep 5, 2010
1 parent 8958f33 commit 3088b4f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,15 @@ def match(*args)
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)
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/resources_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ def test_should_not_allow_invalid_http_methods_for_member_routes
set.draw do
resources :messages do
member do
match :something, :via => :invalid
match :something, :via => [:invalid, :get]
end
end
end
Expand Down

0 comments on commit 3088b4f

Please sign in to comment.