From 1f0a1f65ca4065a4d946e06f7d532a07e7e7f2a6 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sat, 12 Jan 2019 01:34:18 +0000 Subject: [PATCH] Merged r17786 and r17787 from trunk to 3.4-stable (#30412). git-svn-id: http://svn.redmine.org/redmine/branches/3.4-stable@17789 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/import.rb | 1 + test/fixtures/files/import_issues_utf8_with_bom.csv | 4 ++++ test/unit/issue_import_test.rb | 9 +++++++++ 3 files changed, 14 insertions(+) create mode 100644 test/fixtures/files/import_issues_utf8_with_bom.csv diff --git a/app/models/import.rb b/app/models/import.rb index d2c53baac..71bc3c1bb 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -217,6 +217,7 @@ class Import < ActiveRecord::Base csv_options = {:headers => false} csv_options[:encoding] = settings['encoding'].to_s.presence || 'UTF-8' + csv_options[:encoding] = 'bom|UTF-8' if csv_options[:encoding] == 'UTF-8' separator = settings['separator'].to_s csv_options[:col_sep] = separator if separator.size == 1 wrapper = settings['wrapper'].to_s diff --git a/test/fixtures/files/import_issues_utf8_with_bom.csv b/test/fixtures/files/import_issues_utf8_with_bom.csv new file mode 100644 index 000000000..1ab78ac4b --- /dev/null +++ b/test/fixtures/files/import_issues_utf8_with_bom.csv @@ -0,0 +1,4 @@ +"priority";subject;description;start_date;due_date;parent;private;progress;custom;version;category;user;estimated_hours;tracker;status +High;First;First description;2015-07-08;2015-08-25;;no;;PostgreSQL;;New category;dlopper;1;bug;new +Normal;Child 1;Child description;;;1;yes;10;MySQL;2.0;New category;;2;feature request;new +Normal;Child of existing issue;Child description;;;#2;no;20;;2.1;Printing;;3;bug;assigned diff --git a/test/unit/issue_import_test.rb b/test/unit/issue_import_test.rb index 3e0eecae6..52960a366 100644 --- a/test/unit/issue_import_test.rb +++ b/test/unit/issue_import_test.rb @@ -115,6 +115,15 @@ class IssueImportTest < ActiveSupport::TestCase assert_equal 2, issues[2].parent_id end + def test_import_utf8_with_bom + import = generate_import_with_mapping('import_issues_utf8_with_bom.csv') + import.settings.merge!('encoding' => 'UTF-8') + import.save + + issues = new_records(Issue,3) { import.run } + assert_equal 3, issues.count + end + def test_backward_and_forward_reference_to_parent_should_work import = generate_import('import_subtasks.csv') import.settings = { -- 2.39.5