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
Conversation
test/open-uri/test_open-uri.rb
Outdated
@@ -120,6 +120,7 @@ def test_tempfile_rest_parameter | |||
assert_nothing_raised { | |||
temp_file = Tempfile.new | |||
open(temp_file, 'a') | |||
temp_file.close |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use ensure
.
test/open-uri/test_open-uri.rb
Outdated
temp_file = Tempfile.new | ||
assert_nothing_raised { open(temp_file, 'a') } | ||
ensure | ||
temp_file.close |
There was a problem hiding this comment.
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
.
…pull request #1675. Using 'open' with a temp file causes an exception. This is caused by the newly introduced Exchange integration dependencies 'viewpoint' and 'autodiscover' which depend on 'httpclient' which requires 'open-uri' somewhere. These cause the integration tests to fail - namely UserAgentTest#test_check_request. Link: ruby/ruby#1675
As we don't accept patches on maintenance branches directly, please rebase on the trunk, and file an issue at https://bugs.ruby-lang.org/projects/ruby-trunk/issues/new. And, I'm uncertain if it's better to check by the arity of diff --git i/lib/open-uri.rb w/lib/open-uri.rb
index ce608a9296..b445b7bca5 100644
--- i/lib/open-uri.rb
+++ w/lib/open-uri.rb
@@ -27,7 +27,18 @@
# 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) && !name.method(:open).parameters.empty?
+ if name.respond_to?(:to_io)
+ io = name.to_io.dup
+ if block
+ begin
+ yield io
+ ensure
+ io.close
+ end
+ else
+ io
+ end
+ elsif name.respond_to?(:open)
name.open(*rest, &block)
elsif name.respond_to?(:to_str) &&
%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name && |
Closing. Applied changed and feedback in #1680 . |
Hi there,
try this in your current ruby env:
Get this:
Greetings.