diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 8ae64668..5c6b3360 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -63,8 +63,8 @@ module Sinatra # http://rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html class Response < Rack::Response def body=(value) - value = value.body while value.respond_to? :body and value.body != value - @body = value.respond_to?(:to_str) ? [value.to_str] : value + value = value.body while Rack::Response === value + @body = String === value ? [value.to_str] : value end def each @@ -75,7 +75,7 @@ module Sinatra if status.to_i / 100 == 1 headers.delete "Content-Length" headers.delete "Content-Type" - elsif body.respond_to? :to_ary and not [204, 304].include?(status.to_i) + elsif Array === body and not [204, 304].include?(status.to_i) headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s end super @@ -614,7 +614,7 @@ module Sinatra invoke { error_block!(response.status) } unless @response['Content-Type'] - if body.respond_to? :to_ary and body[0].respond_to? :content_type + if Array === body and body[0].respond_to? :content_type content_type body[0].content_type else content_type :html @@ -700,7 +700,7 @@ module Sinatra # Revert params afterwards. # # Returns pass block. - def process_route(pattern, keys, conditions, block = nil) + def process_route(pattern, keys, conditions, block = nil, values = nil) @original_params ||= @params route = @request.path_info route = '/' if route.empty? and not settings.empty_path_info? diff --git a/test/response_test.rb b/test/response_test.rb index 6c70b60a..81537957 100644 --- a/test/response_test.rb +++ b/test/response_test.rb @@ -40,6 +40,15 @@ class ResponseTest < Test::Unit::TestCase assert_equal @response.body, body.body end + it 'does not call #to_ary or #inject on the body' do + object = Object.new + def object.inject(*) fail 'called' end + def object.to_ary(*) fail 'called' end + def object.each(*) end + @response.body = object + assert @response.finish + end + it 'does not nest a Sinatra::Response' do @response.body = Sinatra::Response.new ["foo"] assert_equal @response.body, ["foo"]