From 1c5a2ddfb07cd4993fa9f28542df51a399e29a6c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 21 Feb 2009 16:04:51 +0000 Subject: [PATCH] Limit the size of repository files displayed inline too. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2505 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/repositories_controller.rb | 4 ++-- .../repositories_subversion_controller_test.rb | 12 ++++++++++++ test/test_helper.rb | 7 +++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index e2cdd17b82..3e8ac3e3d4 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -117,8 +117,8 @@ class RepositoriesController < ApplicationController @content = @repository.cat(@path, @rev) show_error_not_found and return unless @content - if 'raw' == params[:format] || @content.is_binary_data? - # Force the download if it's a binary file + if 'raw' == params[:format] || @content.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte) + # Force the download send_data @content, :filename => @path.split('/').last else # Prevent empty lines when displaying a file with Windows style eol diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb index a3918a922c..c2bb403677 100644 --- a/test/functional/repositories_subversion_controller_test.rb +++ b/test/functional/repositories_subversion_controller_test.rb @@ -94,6 +94,16 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase assert_response :success assert_template 'entry' end + + def test_entry_should_send_if_too_big + # no files in the test repo is larger than 1KB... + with_settings :file_max_size_displayed => 0 do + get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] + assert_response :success + assert_template '' + assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] + end + end def test_entry_at_given_revision get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2 @@ -113,6 +123,8 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase def test_entry_download get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw' assert_response :success + assert_template '' + assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] end def test_directory_entry diff --git a/test/test_helper.rb b/test/test_helper.rb index 7d817fb19b..88117e540a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -64,4 +64,11 @@ class Test::Unit::TestCase Dir.mkdir "#{RAILS_ROOT}/tmp/test/attachments" unless File.directory?("#{RAILS_ROOT}/tmp/test/attachments") Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments" end + + def with_settings(options, &block) + saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h} + options.each {|k, v| Setting[k] = v} + yield + saved_settings.each {|k, v| Setting[k] = v} + end end