This project is archived and is in readonly mode.
Integration::Session fails to follow_redirect! because of Rack headers['location] changes
Reported by Christos Zisopoulos | December 11th, 2008 @ 12:13 AM | in 2.x
Given a freshly created edge app and a controller (e.g.
Posts
) that just redirects one URL to another URL
(e.g. /posts/private =302=> /posts/index
) the
following simple steps in an Integration story fail.
get '/posts/private'
assert_response :redirect # passes
follow_redirect! # should try to get /posts/index
assert_response :success # fails with a 404
What happens is that no matter what the URL
follow_redirect!
always tries to get /h
which is actually the wrongly interpreted first character of
http://www.example.com/posts/index
I've tracked the issue down to line 129 of
integration.rb
:
get(interpret_uri(headers['location'].first))
The bug seems to have appeared after this commit:
http://github.com/rails/rails/co...
Before these Rack related changes, calling
headers['location']
would return an Array of Strings.
Now it returns a single String (in my case http://www.example.com/posts/index
)
and calling first on it returns the first character.
Removing the call to first makes my integration story pass but
raises an error in line 35 of integration_test.rb
(test_follow_redirect_calls_get_and_returns_status
):
@session.stubs(:headers).returns({"location" => ["www.google.com"]})
The test can be fixed by removing the square brackets i.e. make
headers['location']
stub return an String.
I am almost certain that the test needs fixing because line 342
of Rack's lint.rb
(Rake::Lint#check_headers
) that states that "header
values must consist of Strings" and it seems to be exactly what is
returned from the @app.call(env)
http://github.com/chneukirchen/r...
I am attaching a tiny patch for this with no extra tests, just the corrected ones, as the dispatch code is way over my head and I can't seem to find a way to test it more end to end. Testing with stubs seems to have hidden the bug in this case...
Comments and changes to this ticket
-
josh December 11th, 2008 @ 12:28 AM
- Assigned user set to josh
- State changed from new to open
-
Repository December 11th, 2008 @ 12:37 AM
- State changed from open to resolved
(from [69387ce0169b95d3a170cfb1c66a7570b1746e37]) Fix for Integration::Session follow_redirect! headers['location'] bug with Rack [#1555 state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1555 Integration::Session fails to follow_redirect! because of Rack headers['location] changes (from [69387ce0169b95d3a170cfb1c66a7570b1746e37]) Fix for...