From 84dcea3309b9e2c0a486377e340137909f551aef Mon Sep 17 00:00:00 2001 From: Nicolas Sanguinetti Date: Mon, 7 Jan 2013 00:30:20 -0200 Subject: [PATCH] Allow URI objects as redirect targets --- lib/sinatra/base.rb | 2 +- test/helpers_test.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 323ff16a..1d46a8d5 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -173,7 +173,7 @@ module Sinatra # 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 diff --git a/test/helpers_test.rb b/test/helpers_test.rb index 94735549..9199c596 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -240,6 +240,17 @@ class HelpersTest < Test::Unit::TestCase 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