Issue #4603 has been updated by yu nobuoka.


Hi,

Nobuyoshi Nakada wrote:
>  Now fixed so that universal_newline: false can work.  What's
>  about the following patch?
>  
> diff --git i/lib/csv.rb w/lib/csv.rb > index 1aad2f3..d51cb55 100644 > --- i/lib/csv.rb > +++ w/lib/csv.rb > @@ -1334,10 +1334,18 @@ class CSV > def self.open(*args) > # find the +options+ Hash > options = if args.last.is_a? Hash then args.pop else Hash.new end > - # default to a binary open mode > - args << "rb" if args.size == 1 and !options.key?(:mode) > - # wrap a File opened with the remaining +args+ > - csv = new(File.open(*args, options), options) > + # wrap a File opened with the remaining +args+ with no newline > + # decorator > + file_opts = {universal_newline: false}.merge(options) > + begin > + f = File.open(*args, file_opts) > + rescue ArgumentError => e > + throw unless /needs binmode/ =~ e.message and args.size == 1 > + args << "rb" > + file_opts = {encoding: Encoding.default_external}.merge(file_opts) > + retry > + end > + csv = new(f, options) In +rescue+ clause, a +throw+ expression is used. Is it correct? I think a +raise+ expression should be used instead. Or my idea is wrong...? ---------------------------------------- Bug #4603: lib/csv.rb: when the :encoding parameter is not provided, the encoding of CSV data is treated as ASCII-8BIT http://redmine.ruby-lang.org/issues/4603 Author: yu nobuoka Status: Assigned Priority: Normal Assignee: James Gray Category: lib Target version: 1.9.2 ruby -v: - This issue is involved in three methods, CSV::open, CSV::read and CSV::foreach. The document of CSV::read says "This method also understands an additional :encoding parameter that you can use to specify the Encoding of the data in the file to be read. You must provide this unless your data is in Encoding::default_external()." However, when the :encoding parameter is not provided, the encoding of the CSV data is treated as ASCII-8BIT. Not as Encoding.default_external. CSV::open and CSV::foreach are also similar. I think the actual behaviour of these methods doesn't conform to the document of these. -- http://redmine.ruby-lang.org