From: mail@stefanschuessler.de
To: ruby-core@ruby-lang.org
Subject: [ruby-core:92817] [Ruby trunk Bug#15872] CSV.parse omits close call when block is given – intended or bug?
Date: Fri, 24 May 2019 09:08:25 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-15872.20190524090824.530f707c24fb8343@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15872.20190524090824@ruby-lang.org
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/
next parent reply other threads:[~2019-05-24 9:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-15872.20190524090824@ruby-lang.org>
2019-05-24 9:08 ` mail [this message]
2019-05-24 10:01 ` [ruby-core:92820] [Ruby trunk Bug#15872] CSV.parse omits close call when block is given – intended or bug? nobu
2019-05-24 21:45 ` [ruby-core:92831] " kou
2019-05-25 17:32 ` [ruby-core:92841] " ruby-core
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-15872.20190524090824.530f707c24fb8343@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).