@@ -264,7 +264,6 module IssuesHelper | |||||
264 | end |
|
264 | end | |
265 |
|
265 | |||
266 | def issues_to_csv(issues, project = nil) |
|
266 | def issues_to_csv(issues, project = nil) | |
267 | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
|
|||
268 | decimal_separator = l(:general_csv_decimal_separator) |
|
267 | decimal_separator = l(:general_csv_decimal_separator) | |
269 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
|
268 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| | |
270 | # csv header fields |
|
269 | # csv header fields | |
@@ -292,7 +291,9 module IssuesHelper | |||||
292 | custom_fields.each {|f| headers << f.name} |
|
291 | custom_fields.each {|f| headers << f.name} | |
293 | # Description in the last column |
|
292 | # Description in the last column | |
294 | headers << l(:field_description) |
|
293 | headers << l(:field_description) | |
295 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
294 | csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8( | |
|
295 | c.to_s, | |||
|
296 | l(:general_csv_encoding) ) } | |||
296 | # csv lines |
|
297 | # csv lines | |
297 | issues.each do |issue| |
|
298 | issues.each do |issue| | |
298 | fields = [issue.id, |
|
299 | fields = [issue.id, | |
@@ -315,7 +316,9 module IssuesHelper | |||||
315 | ] |
|
316 | ] | |
316 | custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) } |
|
317 | custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) } | |
317 | fields << issue.description |
|
318 | fields << issue.description | |
318 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end } |
|
319 | csv << fields.collect {|c| Redmine::CodesetUtil.from_utf8( | |
|
320 | c.to_s, | |||
|
321 | l(:general_csv_encoding) ) } | |||
319 | end |
|
322 | end | |
320 | end |
|
323 | end | |
321 | export |
|
324 | export |
@@ -324,6 +324,41 class IssuesControllerTest < ActionController::TestCase | |||||
324 | end |
|
324 | end | |
325 | end |
|
325 | end | |
326 |
|
326 | |||
|
327 | def test_index_csv_cannot_convert_should_be_replaced_big_5 | |||
|
328 | with_settings :default_language => "zh-TW" do | |||
|
329 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" | |||
|
330 | if str_utf8.respond_to?(:force_encoding) | |||
|
331 | str_utf8.force_encoding('UTF-8') | |||
|
332 | end | |||
|
333 | issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, | |||
|
334 | :status_id => 1, :priority => IssuePriority.all.first, | |||
|
335 | :subject => str_utf8) | |||
|
336 | assert issue.save | |||
|
337 | ||||
|
338 | get :index, :project_id => 1, | |||
|
339 | :f => ['subject'], | |||
|
340 | :op => '=', :values => [str_utf8], | |||
|
341 | :format => 'csv' | |||
|
342 | assert_equal 'text/csv', @response.content_type | |||
|
343 | lines = @response.body.chomp.split("\n") | |||
|
344 | s1 = "\xaa\xac\xbaA" | |||
|
345 | if str_utf8.respond_to?(:force_encoding) | |||
|
346 | s1.force_encoding('Big5') | |||
|
347 | end | |||
|
348 | assert lines[0].include?(s1) | |||
|
349 | s2 = lines[1].split(",")[5] | |||
|
350 | if s1.respond_to?(:force_encoding) | |||
|
351 | s3 = "\xa5H?" | |||
|
352 | s3.force_encoding('Big5') | |||
|
353 | assert_equal s3, s2 | |||
|
354 | elsif RUBY_PLATFORM == 'java' | |||
|
355 | assert_equal "??", s2 | |||
|
356 | else | |||
|
357 | assert_equal "\xa5H???", s2 | |||
|
358 | end | |||
|
359 | end | |||
|
360 | end | |||
|
361 | ||||
327 | def test_index_pdf |
|
362 | def test_index_pdf | |
328 | get :index, :format => 'pdf' |
|
363 | get :index, :format => 'pdf' | |
329 | assert_response :success |
|
364 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now