Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug: Using 'open-uri' with 'tempfile' causes an exception. #1675

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/open-uri.rb
Expand Up @@ -27,7 +27,7 @@ class << self
# We can accept URIs and strings that begin with http://, https:// and
# ftp://. In these cases, the opened file object is extended by OpenURI::Meta.
def open(name, *rest, &block) # :doc:
if name.respond_to?(:open)
if name.respond_to?(:open) && !name.method(:open).parameters.empty?
name.open(*rest, &block)
elsif name.respond_to?(:to_str) &&
%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
Expand Down
8 changes: 8 additions & 0 deletions test/open-uri/test_open-uri.rb
Expand Up @@ -3,6 +3,7 @@
require 'open-uri'
require 'webrick'
require 'webrick/httpproxy'
require 'tempfile'
begin
require 'zlib'
rescue LoadError
Expand Down Expand Up @@ -115,6 +116,13 @@ def test_open_too_many_arg
assert_raise(ArgumentError) { open("http://192.0.2.1/tma", "r", 0666, :extra) {} }
end

def test_tempfile_rest_parameter
temp_file = Tempfile.new
assert_nothing_raised { open(temp_file, 'a') }
ensure
temp_file.close
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use close! instead of close.

end

def test_read_timeout
TCPServer.open("127.0.0.1", 0) {|serv|
port = serv.addr[1]
Expand Down