diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-06-13 07:55:30 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-06-13 07:55:30 +0000 |
commit | 3077ed8d3a79fc613f31ecd47418fcec291cfd18 (patch) | |
tree | 0f8453bf59641e424808c03aae3e135adb202198 | |
parent | 49914f010dfb0ae7245ff2b63ba4655a9e07cd79 (diff) | |
download | redmine-3077ed8d3a79fc613f31ecd47418fcec291cfd18.tar.gz redmine-3077ed8d3a79fc613f31ecd47418fcec291cfd18.zip |
Add BOM to UTF-8 encoded CSV (#7037).
git-svn-id: http://svn.redmine.org/redmine/trunk@14303 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | lib/redmine/export/csv.rb | 8 | ||||
-rw-r--r-- | test/unit/lib/redmine/export/csv_test.rb | 31 |
2 files changed, 38 insertions, 1 deletions
diff --git a/lib/redmine/export/csv.rb b/lib/redmine/export/csv.rb index ce43240ba..3762eb661 100644 --- a/lib/redmine/export/csv.rb +++ b/lib/redmine/export/csv.rb @@ -35,7 +35,13 @@ module Redmine col_sep = l(:general_csv_separator) encoding = l(:general_csv_encoding) - super(:col_sep => col_sep, :encoding => encoding, &block) + str = ''.force_encoding(encoding) + if encoding == 'UTF-8' + # BOM + str = "\xEF\xBB\xBF".force_encoding(encoding) + end + + super(str, :col_sep => col_sep, :encoding => encoding, &block) end end diff --git a/test/unit/lib/redmine/export/csv_test.rb b/test/unit/lib/redmine/export/csv_test.rb new file mode 100644 index 000000000..df200c151 --- /dev/null +++ b/test/unit/lib/redmine/export/csv_test.rb @@ -0,0 +1,31 @@ +# Redmine - project management software +# Copyright (C) 2006-2015 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../../../../test_helper', __FILE__) + +class CsvTest < ActiveSupport::TestCase + + BOM = "\xEF\xBB\xBF".force_encoding('UTF-8') + + def test_should_include_bom_when_utf8_encoded + with_locale 'sk' do + string = Redmine::Export::CSV.generate {|csv| csv << %w(Foo Bar)} + assert_equal 'UTF-8', string.encoding.name + assert string.starts_with?(BOM) + end + end +end |