Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly ignored wildcard verbs from head_routes #18764

Merged
merged 1 commit into from
Feb 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
* Explicitly ignored wildcard verbs when searching for HEAD routes before fallback

Fixes an issue where a mounted rack app at root would intercept the HEAD
request causing an incorrect behavior during the fall back to GET requests.

Example:
```ruby
draw do
get '/home' => 'test#index'
mount rack_app, at: '/'
end
head '/home'
assert_response :success
```
In this case, a HEAD request runs through the routes the first time and fails
to match anything. Then, it runs through the list with the fallback and matches
`get '/home'`. The original behavior would match the rack app in the first pass.

*Terence Sun*

* Migrating xhr methods to keyword arguments syntax
in `ActionController::TestCase` and `ActionDispatch::Integration`

Expand Down
1 change: 1 addition & 0 deletions actionpack/lib/action_dispatch/journey/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def find_routes req
end

def match_head_routes(routes, req)
routes.delete_if { |route| route.verb == // }
head_routes = match_routes(routes, req)

if head_routes.empty?
Expand Down
12 changes: 12 additions & 0 deletions actionpack/test/dispatch/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3477,6 +3477,18 @@ def test_scope_where_as_is_empty
assert_equal '/post/comments/new', new_comment_path
end

def test_head_fetch_with_mount_on_root
draw do
get '/home' => 'test#index'
mount lambda { |env| [404, {"Content-Type" => "text/html"}, ["testing"]] }, at: '/'
end
head '/home'
assert_response :success

head '/'
assert_response :not_found
end

private

def draw(&block)
Expand Down