Do not raise Encoding::UndefinedConversionError during CSV rendering

Use replacement characters instead of exceptions.
This commit is contained in:
Patrick Gansterer 2018-12-11 15:27:32 +01:00
parent a4f5b8fb33
commit d67bbe447f
1 changed files with 3 additions and 2 deletions

View File

@ -13,13 +13,14 @@ class RenderCSV
end end
def to_csv def to_csv
options = @options.select {|k| %w(col_sep row_sep encoding).include? k.to_s} options = @options.select {|k| %w(col_sep row_sep).include? k.to_s}
CSV.generate options do |csv| ret = CSV.generate options do |csv|
if h = header if h = header
csv << h csv << h
end end
data {|d| csv << d} data {|d| csv << d}
end end
ret.encode(@options[:encoding], invalid: :replace, undef: :replace)
end end
def header def header