From 11d2edffe68fdd52d3a8a6bad26f774c9dd27dfa Mon Sep 17 00:00:00 2001 From: nahi Date: Mon, 6 Oct 2003 14:03:58 +0000 Subject: * lib/csv.rb (IOReader, BasicWriter): call binmode when a given IO respond_to?(:binmode). record separator was wrong when you gave text mode IO to Reader.parse and Writer.generate. * test/csv/test_csv.rb: add tests for above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/csv.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/csv.rb') diff --git a/lib/csv.rb b/lib/csv.rb index ee686db0cf..10c86f6417 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -463,6 +463,7 @@ public # def initialize(io, col_sep = ?,, row_sep = nil) @io = io + @io.binmode if @io.respond_to?(:binmode) @col_sep = col_sep @row_sep = row_sep @dev = CSV::IOBuf.new(@io) @@ -551,8 +552,8 @@ public # Create instance. To add CSV data to generate CSV string, see # CSV::Writer#<< or CSV::Writer#add_row. # - def Writer.create(str_or_readable, col_sep = ?,, row_sep = nil) - BasicWriter.new(str_or_readable, col_sep, row_sep) + def Writer.create(str_or_writable, col_sep = ?,, row_sep = nil) + BasicWriter.new(str_or_writable, col_sep, row_sep) end # SYNOPSIS @@ -675,6 +676,7 @@ public @col_sep = col_sep @row_sep = row_sep @dev = str_or_writable + @dev.binmode if @dev.respond_to?(:binmode) @close_on_terminate = false end @@ -1036,7 +1038,7 @@ private when :DT_COLSEP out_dev << col_sep.chr when :DT_ROWSEP - out_dev << (row_sep || "\r\n") + out_dev << (row_sep ? row_sep.chr : "\r\n") end end end -- cgit v1.2.3