Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Append BOM to ensure Excel can open CSV directly & correctly Encoding: UTF-8

Eric Guo93a0f13dd6d5
diff --git a/app/models/exports/concerns/csv.rb b/app/models/exports/concerns/csv.rb
index cc1c7b59e54..859e6e0ccaa 100644
--- a/app/models/exports/concerns/csv.rb
+++ b/app/models/exports/concerns/csv.rb
@@ -53,7 +53,7 @@ module Exports
::Exports::Result
.new format: :csv,
title: csv_export_filename,
- content: serialized,
+ content: "\xEF\xBB\xBF#{serialized}", # Make Excel open CSV happy by append UTF8 BOM
mime_type: "text/csv"
end
diff --git a/spec/models/projects/exporter/csv_integration_spec.rb b/spec/models/projects/exporter/csv_integration_spec.rb
index e578ab18bc6..11dcb17aa1d 100644
--- a/spec/models/projects/exporter/csv_integration_spec.rb
+++ b/spec/models/projects/exporter/csv_integration_spec.rb
@@ -74,7 +74,7 @@ RSpec.describe Projects::Exports::CSV, "integration" do
it "does not render project custom fields in the header" do
expect(parsed.size).to eq 2
- expect(header).to eq ["id", "Identifier", "Name", "Description", "Status", "Public"]
+ expect(header).to eq ["\xEF\xBB\xBFid", "Identifier", "Name", "Description", "Status", "Public"]
end
it "does not render the custom field values in the rows if enabled for a project" do
@@ -93,7 +93,7 @@ RSpec.describe Projects::Exports::CSV, "integration" do
expect(cf_names).not_to include(not_used_string_cf.name)
expect(cf_names).not_to include(hidden_cf.name)
- expect(header).to eq ["id", "Identifier", "Name", "Description", "Status", "Public", *cf_names]
+ expect(header).to eq ["\xEF\xBB\xBFid", "Identifier", "Name", "Description", "Status", "Public", *cf_names]
end
it "renders the custom field values in the rows if enabled for a project" do
@@ -126,7 +126,7 @@ RSpec.describe Projects::Exports::CSV, "integration" do
expect(cf_names).to include(not_used_string_cf.name)
expect(cf_names).to include(hidden_cf.name)
- expect(header).to eq ["id", "Identifier", "Name", "Description", "Status", "Public", *cf_names]
+ expect(header).to eq ["\xEF\xBB\xBFid", "Identifier", "Name", "Description", "Status", "Public", *cf_names]
end
it "renders the custom field values in the rows if enabled for a project" do
diff --git a/spec/models/work_package/exporter/csv_integration_spec.rb b/spec/models/work_package/exporter/csv_integration_spec.rb
index f2c0ef5e416..fb76f70c6b2 100644
--- a/spec/models/work_package/exporter/csv_integration_spec.rb
+++ b/spec/models/work_package/exporter/csv_integration_spec.rb
@@ -124,7 +124,7 @@ RSpec.describe WorkPackage::Exports::CSV, "integration" do
data = CSV.parse instance.export!.content
expect(data.size).to eq(5)
- expect(data.pluck(0)).to eq ["Type", "Type A", "Type A", "Type A", "Type B"]
+ expect(data.pluck(0)).to eq ["\xEF\xBB\xBFType", "Type A", "Type A", "Type A", "Type B"]
end
end
@@ -171,7 +171,7 @@ RSpec.describe WorkPackage::Exports::CSV, "integration" do
data = CSV.parse instance.export!.content
expect(data.size).to eq(5)
- expect(data.pluck(0)).to eq %w[Subject WP4 WP2 WP1 WP3]
+ expect(data.pluck(0)).to eq %w[WP4 WP2 WP1 WP3].unshift("\xEF\xBB\xBFSubject")
end
end
end