From 3c5b67e0db22ec9a15cef6c4961abf6f91373dd3 Mon Sep 17 00:00:00 2001 From: Seiei Miyagi Date: Mon, 25 Nov 2019 10:06:59 +0900 Subject: [ruby/csv] Ensuring StringIO's encoding in CSV.generate (#111) https://github.com/ruby/csv/commit/dbf55ef008 --- lib/csv.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/csv.rb') diff --git a/lib/csv.rb b/lib/csv.rb index 8aa65868b7..c793b8e96a 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -531,12 +531,13 @@ class CSV # plan to output non-ASCII compatible data. # def generate(str=nil, **options) + encoding = options[:encoding] # add a default empty String, if none was given if str str = StringIO.new(str) str.seek(0, IO::SEEK_END) + str.set_encoding(encoding) if encoding else - encoding = options[:encoding] str = +"" str.force_encoding(encoding) if encoding end -- cgit v1.2.3