Do not raise Encoding::UndefinedConversionError during CSV rendering
Use replacement characters instead of exceptions.
This commit is contained in:
parent
a4f5b8fb33
commit
d67bbe447f
1 changed files with 3 additions and 2 deletions
|
@ -13,13 +13,14 @@ class RenderCSV
|
|||
end
|
||||
|
||||
def to_csv
|
||||
options = @options.select {|k| %w(col_sep row_sep encoding).include? k.to_s}
|
||||
CSV.generate options do |csv|
|
||||
options = @options.select {|k| %w(col_sep row_sep).include? k.to_s}
|
||||
ret = CSV.generate options do |csv|
|
||||
if h = header
|
||||
csv << h
|
||||
end
|
||||
data {|d| csv << d}
|
||||
end
|
||||
ret.encode(@options[:encoding], invalid: :replace, undef: :replace)
|
||||
end
|
||||
|
||||
def header
|
||||
|
|
Loading…
Reference in a new issue