From 4ae7f82f3ae13ff01d1581f2a8f271ff294e06be Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Sat, 5 Nov 2011 03:47:03 +0000 Subject: [PATCH] do not annotate text files which exceed the size limit for viewing (#9484) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Contributed by Antonio García-Domínguez. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7728 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/repositories_controller.rb | 11 ++++++++++- config/locales/en-GB.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + test/functional/repositories_git_controller_test.rb | 13 +++++++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index a04498af0..7f346bfd6 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -172,7 +172,16 @@ class RepositoriesController < ApplicationController (show_error_not_found; return) unless @entry @annotate = @repository.scm.annotate(@path, @rev) - (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty? + if @annotate.nil? || @annotate.empty? + (render_error l(:error_scm_annotate); return) + end + ann_buf_size = 0 + @annotate.lines.each do |buf| + ann_buf_size += buf.size + end + if ann_buf_size > Setting.file_max_size_displayed.to_i.kilobyte + (render_error l(:error_scm_annotate_big_text_file); return) + end @changeset = @repository.find_changeset_by_name(@rev) end diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index f5a6dccfa..19ea883a0 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -180,6 +180,7 @@ en-GB: error_scm_not_found: "The entry or revision was not found in the repository." error_scm_command_failed: "An error occurred when trying to access the repository: %{value}" error_scm_annotate: "The entry does not exist or cannot be annotated." + error_scm_annotate_big_text_file: "The entry cannot be annotated, as it exceeds the maximum text file size." error_issue_not_found_in_project: 'The issue was not found or does not belong to this project' error_no_tracker_in_project: 'No tracker is associated to this project. Please check the Project settings.' error_no_default_issue_status: 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").' diff --git a/config/locales/en.yml b/config/locales/en.yml index ee8717057..ee4492550 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -176,6 +176,7 @@ en: error_scm_not_found: "The entry or revision was not found in the repository." error_scm_command_failed: "An error occurred when trying to access the repository: %{value}" error_scm_annotate: "The entry does not exist or cannot be annotated." + error_scm_annotate_big_text_file: "The entry cannot be annotated, as it exceeds the maximum text file size." error_issue_not_found_in_project: 'The issue was not found or does not belong to this project' error_no_tracker_in_project: 'No tracker is associated to this project. Please check the Project settings.' error_no_default_issue_status: 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").' diff --git a/config/locales/es.yml b/config/locales/es.yml index c45675a7d..13a742367 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -245,6 +245,7 @@ es: error_can_t_load_default_data: "No se ha podido cargar la configuración por defecto: %{value}" error_issue_not_found_in_project: 'La petición no se encuentra o no está asociada a este proyecto' error_scm_annotate: "No existe la entrada o no ha podido ser anotada" + error_scm_annotate_big_text_file: "La entrada no puede anotarse, al superar el tamaño máximo para ficheros de texto." error_scm_command_failed: "Se produjo un error al acceder al repositorio: %{value}" error_scm_not_found: "La entrada y/o la revisión no existe en el repositorio." field_account: Cuenta diff --git a/test/functional/repositories_git_controller_test.rb b/test/functional/repositories_git_controller_test.rb index 5eea1d4f7..0a95cbeef 100644 --- a/test/functional/repositories_git_controller_test.rb +++ b/test/functional/repositories_git_controller_test.rb @@ -354,6 +354,19 @@ class RepositoriesGitControllerTest < ActionController::TestCase :content => /cannot be annotated/ end + def test_annotate_error_when_too_big + with_settings :file_max_size_displayed => 1 do + get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 'deff712f' + assert_response 500 + assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, + :content => /exceeds the maximum text file size/ + + get :annotate, :id => PRJ_ID, :path => ['README'], :rev => '7234cb2' + assert_response :success + assert_template 'annotate' + end + end + def test_annotate_latin_1 if @ruby19_non_utf8_pass puts_ruby19_non_utf8_pass() -- 2.39.5