##// END OF EJS Templates
Add BOM to UTF-8 encoded CSV (#7037)....
Jean-Philippe Lang -
r13921:3077ed8d3a79
parent child
Show More
@@ -0,0 +1,31
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../../../../test_helper', __FILE__)
19
20 class CsvTest < ActiveSupport::TestCase
21
22 BOM = "\xEF\xBB\xBF".force_encoding('UTF-8')
23
24 def test_should_include_bom_when_utf8_encoded
25 with_locale 'sk' do
26 string = Redmine::Export::CSV.generate {|csv| csv << %w(Foo Bar)}
27 assert_equal 'UTF-8', string.encoding.name
28 assert string.starts_with?(BOM)
29 end
30 end
31 end
@@ -35,7 +35,13 module Redmine
35 col_sep = l(:general_csv_separator)
35 col_sep = l(:general_csv_separator)
36 encoding = l(:general_csv_encoding)
36 encoding = l(:general_csv_encoding)
37
37
38 super(:col_sep => col_sep, :encoding => encoding, &block)
38 str = ''.force_encoding(encoding)
39 if encoding == 'UTF-8'
40 # BOM
41 str = "\xEF\xBB\xBF".force_encoding(encoding)
42 end
43
44 super(str, :col_sep => col_sep, :encoding => encoding, &block)
39 end
45 end
40 end
46 end
41
47
General Comments 0
You need to be logged in to leave comments. Login now