diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-04-27 21:07:09 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-04-27 21:07:09 +0000 |
commit | e858442f4f9ca8dead0413a8fa140be92240f189 (patch) | |
tree | 5e42ae9012b4e5cf8856a1806fb8773e14848d5d /lib | |
parent | 2f348762fbcf97b1de3b91c0dd84ba8b8b430dfd (diff) | |
download | ruby-e858442f4f9ca8dead0413a8fa140be92240f189.tar.gz |
* lib/csv.rb (CSV::open): suppress universal newline decorator.
fixes #4603
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/csv.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index 085ee8433d..8925de8293 100644 --- a/lib/csv.rb +++ b/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 + raise 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) # handle blocks like Ruby's open(), not like the CSV library if block_given? |