From 50d055c2f241ef08a28fb5d361fb7717689e5845 Mon Sep 17 00:00:00 2001 From: Igor Fedoronchuk Date: Mon, 19 Jan 2015 14:10:49 +0200 Subject: [PATCH] win1251 specs --- lib/active_admin_import/model.rb | 13 ++++++++++--- .../files/authors_win1251_win_endline.csv | 3 +++ spec/import_spec.rb | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 spec/fixtures/files/authors_win1251_win_endline.csv diff --git a/lib/active_admin_import/model.rb b/lib/active_admin_import/model.rb index 1057e38..a5f173f 100644 --- a/lib/active_admin_import/model.rb +++ b/lib/active_admin_import/model.rb @@ -132,9 +132,16 @@ def define_methods_for(attr_name) end def encode(data) - data.encode(force_encoding, "binary", - invalid: :replace, undef: :replace, replace: ""). - sub("\xEF\xBB\xBF", "") + data = data.force_encoding("UTF-8") + unless data.valid_encoding? + data = data.encode(force_encoding, + invalid: :replace, undef: :replace, replace: "") + end + begin + data.sub("\xEF\xBB\xBF", "") # bom + rescue ArgumentError => _ + data + end end class <