diff options
author | Kouhei Sutou <kou@clear-code.com> | 2019-04-17 22:02:40 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-07-14 23:07:31 +0900 |
commit | 8392592a0a33bb9103a7aa968389fe50e304e062 (patch) | |
tree | abfbbf1cc870222be6bf5caf022e525bd4ec2506 /lib | |
parent | 9171f833054cd47842e12fc0fd3cc1df704a9192 (diff) |
[ruby/csv] Don't raise on eof?
GitHub: fix #86
Reported by krororo. Thanks!!!
https://github.com/ruby/csv/commit/5a8d9d9297
Diffstat (limited to 'lib')
-rw-r--r-- | lib/csv.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index 1239554ad6..ff317d8995 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -955,6 +955,8 @@ class CSV strip: strip, } @parser = nil + @parser_enumerator = nil + @eof_error = nil @writer_options = { encoding: @encoding, @@ -1156,9 +1158,13 @@ class CSV end def eof? + return false if @eof_error begin parser_enumerator.peek false + rescue MalformedCSVError => error + @eof_error = error + false rescue StopIteration true end @@ -1169,6 +1175,7 @@ class CSV def rewind @parser = nil @parser_enumerator = nil + @eof_error = nil @writer.rewind if @writer @io.rewind end @@ -1264,6 +1271,10 @@ class CSV # The data source must be open for reading. # def shift + if @eof_error + eof_error, @eof_error = @eof_error, nil + raise eof_error + end begin parser_enumerator.next rescue StopIteration |