Feature #44400 » 0001-Send-PDF-compatible-Illustrator-files-as-application.patch
| app/controllers/attachments_controller.rb | ||
|---|---|---|
|
end
|
||
|
if stale?(:etag => @attachment.digest, :template => false)
|
||
|
# PDF compatible files, such as Illustrator files, must be sent as PDF
|
||
|
# when displayed inline because browsers do not display them otherwise
|
||
|
is_inline_pdf = disposition(@attachment) == 'inline' && @attachment.pdf_previewable?
|
||
|
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
||
|
:type => detect_content_type(@attachment),
|
||
|
:type => is_inline_pdf ? 'application/pdf' : detect_content_type(@attachment),
|
||
|
:disposition => disposition(@attachment)
|
||
|
end
|
||
|
end
|
||
| ... | ... | |
|
content_type =
|
||
|
Redmine::MimeType.of(attachment.filename).presence ||
|
||
|
"application/octet-stream"
|
||
|
elsif Marcel::Magic.child?(content_type, "application/pdf")
|
||
|
# Send PDF compatible files, such as Illustrator files, as PDF so that
|
||
|
# browsers display them inline
|
||
|
content_type = "application/pdf"
|
||
|
end
|
||
|
if is_thumb && !content_type.start_with?("image/")
|
||
| ... | ... | |
|
# Inline disposition can be requested only for PDF compatible files (used
|
||
|
# by the PDF preview), to prevent XSS with e.g. HTML or SVG files
|
||
|
def disposition(attachment)
|
||
|
if params[:disposition] == 'inline' && detect_content_type(attachment) == 'application/pdf'
|
||
|
if params[:disposition] == 'inline' && attachment.pdf_previewable?
|
||
|
'inline'
|
||
|
else
|
||
|
'attachment'
|
||
| test/functional/attachments_controller_test.rb | ||
|---|---|---|
|
assert_select 'div.filecontent.pdf object[type=?]', 'application/pdf'
|
||
|
end
|
||
|
def test_download_pdf_compatible_illustrator_file_with_inline_disposition_param_should_be_sent_inline_as_pdf
|
||
|
def test_download_pdf_compatible_illustrator_file_should_be_sent_as_pdf_only_with_inline_disposition_param
|
||
|
set_tmp_attachments_directory
|
||
|
attachment = Attachment.create!(
|
||
|
:file => mock_file_with_options(
|
||
| ... | ... | |
|
:container => Issue.find(1)
|
||
|
)
|
||
|
get(:download, :params => {:id => attachment.id})
|
||
|
assert_response :success
|
||
|
assert_equal 'application/illustrator', @response.media_type
|
||
|
assert_match %r{\Aattachment}, @response.headers['Content-Disposition']
|
||
|
get(:download, :params => {:id => attachment.id, :disposition => 'inline'})
|
||
|
assert_response :success
|
||
|
assert_equal 'application/pdf', @response.media_type
|
||
- « Previous
- 1
- 2
- 3
- 4
- Next »