Skip to content

Commit

Permalink
Merge pull request #1137 from aselder/fix-frozen-string-send-file
Browse files Browse the repository at this point in the history
Don't blow up when passing frozen string to send_file disposition.
  • Loading branch information
namusyaka committed Aug 4, 2018
2 parents 180158b + 0fd085c commit 89d0ff1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Expand Up @@ -360,7 +360,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
Expand Down
6 changes: 6 additions & 0 deletions test/helpers_test.rb
Expand Up @@ -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'
Expand Down

0 comments on commit 89d0ff1

Please sign in to comment.