소스 검색

Rescue any EncodingError exceptions (#25861).

git-svn-id: http://svn.redmine.org/redmine/trunk@16572 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/3.4.0
Jean-Philippe Lang 7 년 전
부모
커밋
ccb9d4ada9
3개의 변경된 파일13개의 추가작업 그리고 1개의 파일을 삭제
  1. 1
    1
      app/controllers/imports_controller.rb
  2. 1
    0
      test/fixtures/files/invalid-Shift_JIS.csv
  3. 11
    0
      test/functional/imports_controller_test.rb

+ 1
- 1
app/controllers/imports_controller.rb 파일 보기

@@ -52,7 +52,7 @@ class ImportsController < ApplicationController

rescue CSV::MalformedCSVError => e
flash.now[:error] = l(:error_invalid_csv_file_or_settings)
rescue ArgumentError, Encoding::InvalidByteSequenceError => e
rescue ArgumentError, EncodingError => e
flash.now[:error] = l(:error_invalid_file_encoding, :encoding => ERB::Util.h(@import.settings['encoding']))
rescue SystemCallError => e
flash.now[:error] = l(:error_can_not_read_import_file)

+ 1
- 0
test/fixtures/files/invalid-Shift_JIS.csv 파일 보기

@@ -0,0 +1 @@
Ȁ

+ 11
- 0
test/functional/imports_controller_test.rb 파일 보기

@@ -102,6 +102,17 @@ class ImportsControllerTest < Redmine::ControllerTest
assert_select 'div#flash_error', /not a valid UTF-8 encoded file/
end

def test_post_settings_with_invalid_encoding_should_display_error
import = generate_import('invalid-Shift_JIS.csv')

post :settings, :id => import.to_param,
:import_settings => {:separator => ";", :wrapper => '"', :encoding => "Shift_JIS"}
assert_response 200
import.reload
assert_nil import.total_items
assert_select 'div#flash_error', /not a valid Shift_JIS encoded file/
end

def test_get_mapping_should_display_mapping_form
import = generate_import('import_iso8859-1.csv')
import.settings = {'separator' => ";", 'wrapper' => '"', 'encoding' => "ISO-8859-1"}

Loading…
취소
저장