[前][次][番号順一覧][スレッド一覧]

ruby-changes:33754

From: akr <ko1@a...>
Date: Tue, 6 May 2014 01:38:59 +0900 (JST)
Subject: [ruby-changes:33754] akr:r45835 (trunk): * lib/open-uri.rb (OpenURI.open_uri): Call StringIO#close only if

akr	2014-05-06 01:38:53 +0900 (Tue, 06 May 2014)

  New Revision: 45835

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45835

  Log:
    * lib/open-uri.rb (OpenURI.open_uri): Call StringIO#close only if
      the StringIO object is not closed yet.
      Reported by Jordi Massaguer Pla.  [ruby-core:42538] [Bug #6010]

  Modified files:
    trunk/ChangeLog
    trunk/lib/open-uri.rb
    trunk/test/open-uri/test_open-uri.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45834)
+++ ChangeLog	(revision 45835)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue May  6 01:28:14 2014  Tanaka Akira  <akr@f...>
+
+	* lib/open-uri.rb (OpenURI.open_uri): Call StringIO#close only if
+	  the StringIO object is not closed yet.
+	  Reported by Jordi Massaguer Pla.  [ruby-core:42538] [Bug #6010]
+
 Tue May  6 01:08:01 2014  Koichi Sasada  <ko1@a...>
 
 	* benchmark/driver.rb: define File::NULL if not defiend and /dev/null
Index: lib/open-uri.rb
===================================================================
--- lib/open-uri.rb	(revision 45834)
+++ lib/open-uri.rb	(revision 45835)
@@ -155,7 +155,7 @@ module OpenURI https://github.com/ruby/ruby/blob/trunk/lib/open-uri.rb#L155
         if io.respond_to? :close!
           io.close! # Tempfile
         else
-          io.close
+          io.close if !io.closed?
         end
       end
     else
Index: test/open-uri/test_open-uri.rb
===================================================================
--- test/open-uri/test_open-uri.rb	(revision 45834)
+++ test/open-uri/test_open-uri.rb	(revision 45835)
@@ -163,6 +163,29 @@ class TestOpenURI < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/open-uri/test_open-uri.rb#L163
     }
   end
 
+  def test_close_in_block_small
+    with_http {|srv, dr, url|
+      srv.mount_proc("/close200", lambda { |req, res| res.body = "close200" } )
+      assert_nothing_raised {
+        open("#{url}/close200") {|f|
+          f.close
+        }
+      }
+    }
+  end
+
+  def test_close_in_block_big
+    with_http {|srv, dr, url|
+      content = "close200big"*10240
+      srv.mount_proc("/close200big", lambda { |req, res| res.body = content } )
+      assert_nothing_raised {
+        open("#{url}/close200big") {|f|
+          f.close
+        }
+      }
+    }
+  end
+
   def test_header
     myheader1 = 'barrrr'
     myheader2 = nil

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]