Skip to content

Enconding error on Ruby 2.7 #121

@MatheusRich

Description

@MatheusRich

I have an application running on Ruby 2.6.6. I'm using the CSV lib like this, and it works fine:

CSV.read(@params[:csv_file].tempfile, headers: true, col_sep: ';', encoding: 'ISO8859-1:utf-8')

Since I upgraded to Ruby 2.7.1 I got this error


NoMethodError:
  undefined method `close' for #<String:0x0000558b5db78160>
  Did you mean?  clone
# ./app/services/admin/batch_search_service.rb:15:in `batch_search'
# ./app/services/admin/batch_search_service.rb:9:in `search'
# ./spec/services/admin/batch_search_service_spec.rb:7:in `block (3 levels) in <top (required)>'
# ./spec/services/admin/batch_search_service_spec.rb:140:in `block (4 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# ArgumentError:
#   unknown encoding name - ISO8859-1:utf-8
#   ./app/services/admin/batch_search_service.rb:15:in `batch_search'

However, If I use the explicit params it works:

CSV.read(@params[:csv_file].tempfile, headers: true, col_sep: ';', external_encoding: 'ISO8859-1', internal_encoding: 'utf-8')

I saw no breaking change on the changelog so I'm assuming that this is not expected.

Ruby version:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux-musl]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions