Merge pull request #7503 from opf/fix/unicode-attachments-content-disposition

Fix/unicode attachments content disposition
pull/7508/head
ulferts 5 years ago committed by GitHub
commit 58f15db512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/attachment.rb
  2. 4
      spec/models/attachment_spec.rb
  3. 2
      spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb

@ -81,7 +81,9 @@ class Attachment < ActiveRecord::Base
end
def content_disposition
inlineable? ? "inline" : "attachment; filename=#{self[:file]}"
# Do not use filename with attachment as this may break for Unicode files
# specifically when using S3 for attachments.
inlineable? ? "inline" : "attachment"
end
def visible?(user = User.current)

@ -290,8 +290,8 @@ describe Attachment, type: :model do
before { binary_attachment.save! }
it "should make S3 use content_disposition 'attachment; filename=...'" do
expect(binary_attachment.content_disposition).to eq "attachment; filename=textfile.txt.gz"
expect(binary_attachment.external_url.to_s).to include "response-content-disposition=attachment%3B%20filename%3Dtextfile.txt.gz"
expect(binary_attachment.content_disposition).to eq "attachment"
expect(binary_attachment.external_url.to_s).to include "response-content-disposition=attachment"
end
end
end

@ -294,7 +294,7 @@ shared_examples 'an APIv3 attachment resource', type: :request, content_type: :j
context 'for a local binary file' do
it_behaves_like 'for a local file' do
let(:mock_file) { FileHelpers.mock_uploaded_file name: 'foobar.dat', content_type: "application/octet-stream" }
let(:content_disposition) { "attachment; filename=#{mock_file.original_filename}" }
let(:content_disposition) { "attachment" }
end
end

Loading…
Cancel
Save