]> source.dussan.org Git - redmine.git/commitdiff
Fix: ImportsControllerTest fails with csv gem 1.0.2 (#28689).
authorGo MAEDA <maeda@farend.jp>
Sun, 6 May 2018 07:48:31 +0000 (07:48 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 6 May 2018 07:48:31 +0000 (07:48 +0000)
Patch by Go MAEDA.

git-svn-id: http://svn.redmine.org/redmine/trunk@17326 e93f8b46-1217-0410-a6f0-8f06a7374b81

Gemfile
app/controllers/imports_controller.rb

diff --git a/Gemfile b/Gemfile
index a3f99a1eccc08cdd987b827077a1ada2112462da..2f717dab35a4a1443fc0d33a83242f5479e1e0f2 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -13,7 +13,7 @@ gem "roadie-rails", "~> 1.2.1"
 gem "roadie", "~> 3.2.1"
 gem "mimemagic"
 gem "mail", "~> 2.6.4"
-gem "csv", "~> 1.0.1" if RUBY_VERSION >= "2.5"
+gem "csv", "~> 1.0.2" if RUBY_VERSION >= "2.3"
 
 gem "nokogiri", "~> 1.8.0"
 gem "i18n", "~> 0.7.0"
index 661eb7405df53e2ff5f14f8c9dcd7164d5395280..7f6a512f6b4755647a989b81269c83f1b8d8f486 100644 (file)
@@ -50,10 +50,13 @@ class ImportsController < ApplicationController
       redirect_to import_mapping_path(@import)
     end
 
-  rescue CSV::MalformedCSVError => e
-    flash.now[:error] = l(:error_invalid_csv_file_or_settings)
-  rescue ArgumentError, EncodingError => e
-    flash.now[:error] = l(:error_invalid_file_encoding, :encoding => ERB::Util.h(@import.settings['encoding']))
+  # TODO: Remove ArgumentError when support for Ruby 2.2 is dropped (#28689)
+  rescue CSV::MalformedCSVError, ArgumentError, EncodingError => e
+    if e.is_a?(CSV::MalformedCSVError) && e.message !~ /Invalid byte sequence/
+      flash.now[:error] = l(:error_invalid_csv_file_or_settings)
+    else
+      flash.now[:error] = l(:error_invalid_file_encoding, :encoding => ERB::Util.h(@import.settings['encoding']))
+    end
   rescue SystemCallError => e
     flash.now[:error] = l(:error_can_not_read_import_file)
   end