]> source.dussan.org Git - redmine.git/commitdiff
Merged r16572 (#25861).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 6 Jun 2017 20:56:38 +0000 (20:56 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 6 Jun 2017 20:56:38 +0000 (20:56 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@16617 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/imports_controller.rb
test/fixtures/files/invalid-Shift_JIS.csv [new file with mode: 0644]
test/functional/imports_controller_test.rb

index 75d4da93300c0dc43a85d1bf271ee81b84a99880..079bce347e62fff77723fd2c03e3e2565ce84aa8 100644 (file)
@@ -50,7 +50,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)
diff --git a/test/fixtures/files/invalid-Shift_JIS.csv b/test/fixtures/files/invalid-Shift_JIS.csv
new file mode 100644 (file)
index 0000000..b759171
--- /dev/null
@@ -0,0 +1 @@
\ No newline at end of file
index 5c41c10d7f86b143e2debfc7a0990d5512a618e5..b3d06b84c2fa71b97337821c067e723fd52d4aac 100644 (file)
@@ -100,6 +100,17 @@ class ImportsControllerTest < ActionController::TestCase
     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"}