Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #605 from foca/master

Allow URI objects as redirect targets
  • Loading branch information...
commit 9984d0d2b3f1ea12273c6c25f8e102b2329f33e9 2 parents 3d0cef2 + 84dcea3
@rkh rkh authored
Showing with 12 additions and 1 deletion.
  1. +1 −1  lib/sinatra/base.rb
  2. +11 −0 test/helpers_test.rb
View
2  lib/sinatra/base.rb
@@ -173,7 +173,7 @@ def redirect(uri, *args)
# According to RFC 2616 section 14.30, "the field value consists of a
# single absolute URI"
- response['Location'] = uri(uri, settings.absolute_redirects?, settings.prefixed_redirects?)
+ response['Location'] = uri(uri.to_s, settings.absolute_redirects?, settings.prefixed_redirects?)
halt(*args)
end
View
11 test/helpers_test.rb
@@ -240,6 +240,17 @@ def status_app(code, &block)
assert_equal '', body
assert_equal 'mailto:jsmith@example.com', response['Location']
end
+
+ it 'accepts a URI object instead of a String' do
+ mock_app do
+ get('/') { redirect URI.parse('http://sinatrarb.com') }
+ end
+
+ get '/'
+ assert_equal 302, status
+ assert_equal '', body
+ assert_equal 'http://sinatrarb.com', response['Location']
+ end
end
describe 'error' do
Please sign in to comment.
Something went wrong with that request. Please try again.