diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-22 06:40:59 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-22 06:40:59 +0000 |
commit | ede0df3a9b38d18f46aecf70075dda688c9bd4c1 (patch) | |
tree | a7f8ee274d16bf1d870650005950a240f5f04c10 | |
parent | 20aed4495bfa0a1f7844501c9118bd2369fe460b (diff) |
Gracefully handle CSV IO when file descriptor closed.
[Bug #10504][ruby-core:66240]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | lib/csv.rb | 2 | ||||
-rwxr-xr-x | test/csv/test_interface.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index b16e817d09..20c9f152a8 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1291,7 +1291,7 @@ class CSV begin yield csv ensure - csv.close + csv.closed? || csv.close end else csv diff --git a/test/csv/test_interface.rb b/test/csv/test_interface.rb index f2c774f606..be27fcd616 100755 --- a/test/csv/test_interface.rb +++ b/test/csv/test_interface.rb @@ -137,6 +137,14 @@ class TestCSV::Interface < TestCSV end end + def test_open_handles_prematurely_closed_file_descriptor_gracefully + assert_nothing_raised(Exception) do + CSV.open(@path) do |csv| + csv.close + end + end + end + ### Test Write Interface ### def test_generate |