Defect #42839 » 42839.patch
| app/controllers/repositories_controller.rb | ||
|---|---|---|
|
# Force the download
|
||
|
send_opt = {:filename => filename_for_content_disposition(@path.split('/').last)}
|
||
|
send_type = Redmine::MimeType.of(@path)
|
||
|
send_opt[:type] = send_type.to_s if send_type
|
||
|
case send_type
|
||
|
when nil
|
||
|
# No MIME type detected. Let Rails use the default type.
|
||
|
when 'application/javascript'
|
||
|
# Avoid ActionController::InvalidCrossOriginRequest exception by forcing download
|
||
|
send_opt[:type] = 'application/octet-stream'
|
||
|
else
|
||
|
send_opt[:type] = send_type
|
||
|
end
|
||
|
send_opt[:disposition] = disposition(@path)
|
||
|
send_data @repository.cat(@path, @rev), send_opt
|
||
|
else
|
||
| test/functional/repositories_subversion_controller_test.rb | ||
|---|---|---|
|
assert_equal "attachment; filename=\"helloworld.c\"; filename*=UTF-8''helloworld.c", @response.headers['Content-Disposition']
|
||
|
end
|
||
|
def test_entry_download_should_force_download_for_js_files
|
||
|
# JavaScript files should be served as 'application/octet-stream'
|
||
|
# to avoid ActionController::InvalidCrossOriginRequest exception
|
||
|
assert_equal 0, @repository.changesets.count
|
||
|
@repository.fetch_changesets
|
||
|
@project.reload
|
||
|
assert_equal NUM_REV, @repository.changesets.count
|
||
|
get(
|
||
|
:raw,
|
||
|
:params => {
|
||
|
:id => PRJ_ID,
|
||
|
:repository_id => @repository.id,
|
||
|
:path => repository_path_hash(['subversion_test', 'foo.js'])[:param]
|
||
|
}
|
||
|
)
|
||
|
assert_response :success
|
||
|
assert_equal 'application/octet-stream', @response.media_type
|
||
|
assert_match /attachment/, @response.headers['Content-Disposition']
|
||
|
end
|
||
|
def test_directory_entry
|
||
|
assert_equal 0, @repository.changesets.count
|
||
|
@repository.fetch_changesets
|
||