ruby / csv

CSV Reading and Writing
https://ruby.github.io/csv/
BSD 2-Clause "Simplified" License
181 stars 114 forks source link

CSV parser ignores the stream position of a StringIO #99

Closed knu closed 5 years ago

knu commented 5 years ago

The CSV parser seems to call @input.string if @input is a StringIO, but I think it should check if @input.pos is zero before doing that.

require 'csv'
require 'stringio'

strio = StringIO.new(<<'EOF')
aaa,b,c
EOF

p strio.read(2) #=> "aa"
p strio.pos #=> 2
p CSV.parse_line(strio) #=> ["aaa", "b", "c"] (["a", "b", "c"] is expected)

This problem was found by @katsyoshi and presented on ruby-jp.slack.com. I tracked it down and identified the causing commit as eeab2ede, which was between v3.0.1 and v3.0.2.

kou commented 5 years ago

Thanks for your report. This is duplicated: #98

knu commented 5 years ago

I only checked for the issues list and overlooked that. Sorry!