From fdf6e8547b6b5cb8da4ac0ae6c29377813af80bb Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Thu, 17 Nov 2011 07:01:40 +0000 Subject: [PATCH] attachment: add a functional test to show invalid UTF-8 text file (#2371) Stripping invalid UTF-8 is Redmine 1.2 behaviour. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7824 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/fixtures/files/iso8859-1.txt | 13 +++++++++++++ test/functional/attachments_controller_test.rb | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/fixtures/files/iso8859-1.txt diff --git a/test/fixtures/files/iso8859-1.txt b/test/fixtures/files/iso8859-1.txt new file mode 100644 index 000000000..9bade6ab9 --- /dev/null +++ b/test/fixtures/files/iso8859-1.txt @@ -0,0 +1,13 @@ +Index: trunk/app/controllers/issues_controller.rb +=================================================================== +--- trunk/app/controllers/issues_controller.rb (révision 1483) ++++ trunk/app/controllers/issues_controller.rb (révision 1484) +@@ -149,7 +149,7 @@ + attach_files(@issue, params[:attachments]) + flash[:notice] = 'Demande créée avec succès' + Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added') +- redirect_to :controller => 'issues', :action => 'show', :id => @issue, :project_id => @project ++ redirect_to :controller => 'issues', :action => 'show', :id => @issue + return + end + end diff --git a/test/functional/attachments_controller_test.rb b/test/functional/attachments_controller_test.rb index 514cc107a..034a090a6 100644 --- a/test/functional/attachments_controller_test.rb +++ b/test/functional/attachments_controller_test.rb @@ -91,6 +91,23 @@ class AttachmentsControllerTest < ActionController::TestCase :sibling => { :tag => 'td', :content => /#{str_japanese}/ } end + def test_show_text_file_should_strip_non_utf8_content + a = Attachment.new(:container => Issue.find(1), + :file => uploaded_test_file("iso8859-1.txt", "text/plain"), + :author => User.find(1)) + assert a.save + assert_equal 'iso8859-1.txt', a.filename + + get :show, :id => a.id + assert_response :success + assert_template 'file' + assert_equal 'text/html', @response.content_type + assert_tag :tag => 'th', + :content => '7', + :attributes => { :class => 'line-num' }, + :sibling => { :tag => 'td', :content => /Demande cre avec succs/ } + end + def test_show_text_file_should_send_if_too_big Setting.file_max_size_displayed = 512 Attachment.find(4).update_attribute :filesize, 754.kilobyte -- 2.39.5