fix malformed time entry report csv encoding in case of unable to convert (#8549)

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7820 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA committed 2011-11-16 08:29:18 +00:00
1 parent 4b5d50e40a
commit 4a3581c748
2 files changed
+54 -7

No files matched your search

+6 -7
View File
@@ -147,7 +147,9 @@ module TimelogHelper
headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
headers += periods
headers << l(:label_total)
csv << headers.collect {|c| to_utf8(c) }
csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8(
c.to_s,
l(:general_csv_encoding) ) }
# Content
report_criteria_to_csv(csv, criterias, periods, hours)
# Total row
@@ -169,7 +171,9 @@ module TimelogHelper
hours_for_value = select_hours(hours, criterias[level], value)
next if hours_for_value.empty?
row = [''] * level
row << to_utf8(format_criteria_value(criterias[level], value))
row << Redmine::CodesetUtil.from_utf8(
format_criteria_value(criterias[level], value).to_s,
l(:general_csv_encoding) )
row += [''] * (criterias.length - level - 1)
total = 0
periods.each do |period|
@@ -185,9 +189,4 @@ module TimelogHelper
end
end
end
def to_utf8(s)
@ic ||= Iconv.new(l(:general_csv_encoding), 'UTF-8')
begin; @ic.iconv(s.to_s); rescue; s.to_s; end
end
end