1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-12-19 15:01:14 +00:00

Rescue any EncodingError exceptions (#25861).

git-svn-id: http://svn.redmine.org/redmine/trunk@16572 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2017-05-27 08:40:39 +00:00
parent 86fa4e66c9
commit ccb9d4ada9
3 changed files with 13 additions and 1 deletions

View File

@ -52,7 +52,7 @@ class ImportsController < ApplicationController
rescue CSV::MalformedCSVError => e rescue CSV::MalformedCSVError => e
flash.now[:error] = l(:error_invalid_csv_file_or_settings) 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'])) flash.now[:error] = l(:error_invalid_file_encoding, :encoding => ERB::Util.h(@import.settings['encoding']))
rescue SystemCallError => e rescue SystemCallError => e
flash.now[:error] = l(:error_can_not_read_import_file) flash.now[:error] = l(:error_can_not_read_import_file)

View File

@ -0,0 +1 @@
Ȁ
1 Ȁ

View File

@ -102,6 +102,17 @@ class ImportsControllerTest < Redmine::ControllerTest
assert_select 'div#flash_error', /not a valid UTF-8 encoded file/ assert_select 'div#flash_error', /not a valid UTF-8 encoded file/
end 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 def test_get_mapping_should_display_mapping_form
import = generate_import('import_iso8859-1.csv') import = generate_import('import_iso8859-1.csv')
import.settings = {'separator' => ";", 'wrapper' => '"', 'encoding' => "ISO-8859-1"} import.settings = {'separator' => ";", 'wrapper' => '"', 'encoding' => "ISO-8859-1"}