diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index c302031df2..168c34149f 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -358,7 +358,7 @@ def content_type(type = nil, params = {}) # Set the Content-Disposition to "attachment" with the specified filename, # instructing the user agents to prompt to save. def attachment(filename = nil, disposition = :attachment) - response['Content-Disposition'] = disposition.to_s + response['Content-Disposition'] = disposition.to_s.dup if filename params = '; filename="%s"' % File.basename(filename) response['Content-Disposition'] << params diff --git a/test/helpers_test.rb b/test/helpers_test.rb index 3575e945cd..86d6d0a438 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -879,6 +879,12 @@ def send_file_app(opts={}) assert_equal 'inline; filename="file.txt"', response['Content-Disposition'] end + it "does not raise an error when :disposition set to a frozen string" do + send_file_app :disposition => 'inline'.freeze + get '/file.txt' + assert_equal 'inline; filename="file.txt"', response['Content-Disposition'] + end + it "sets the Content-Disposition header when :filename provided" do send_file_app :filename => 'foo.txt' get '/file.txt'