From: mail@... Date: 2019-05-24T09:08:25+00:00 Subject: [ruby-core:92817] [Ruby trunk Bug#15872] CSV.parse omits close call when block is given – intended or bug? Issue #15872 has been reported by sos4nt (Stefan Sch����ler). ---------------------------------------- Bug #15872: CSV.parse omits close call when block is given ��� intended or bug? https://bugs.ruby-lang.org/issues/15872 * Author: sos4nt (Stefan Sch����ler) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- The current implementation of `CSV.parse` doesn't call `close` when a block is given: ```ruby def self.parse(*args, &block) csv = new(*args) return csv.each(&block) if block_given? begin csv.read ensure csv.close # <- never gets here if block is given end end ``` A possible fix would be: ```ruby def self.parse(*args, &block) csv = new(*args) if block_given? csv.each(&block) else csv.read end ensure csv.close end ``` But I'm not sure if this behavior might be intended, given that Ruby's CSV library is quite mature. Am I missing a use case or is this actually a bug? -- https://bugs.ruby-lang.org/ Unsubscribe: