Skip to content

Commit

Permalink
Remove the deprecated override of Kernel#open in open-uri
Browse files Browse the repository at this point in the history
This was deprecated in 2.7 to resolve [Misc #15893].
  • Loading branch information
jeremyevans authored and hsbt committed Sep 11, 2020
1 parent 0619c7a commit 53862fa
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
25 changes: 1 addition & 24 deletions lib/open-uri.rb
Expand Up @@ -3,27 +3,6 @@
require 'stringio'
require 'time'

module Kernel
private
alias open_uri_original_open open # :nodoc:
class << self
alias open_uri_original_open open # :nodoc:
end

def open(name, *rest, **kw, &block) # :nodoc:
if (name.respond_to?(:open) && !name.respond_to?(:to_path)) ||
(name.respond_to?(:to_str) &&
%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
(uri = URI.parse(name)).respond_to?(:open))
warn('calling URI.open via Kernel#open is deprecated, call URI.open directly or use URI#open', uplevel: 1)
URI.open(name, *rest, **kw, &block)
else
open_uri_original_open(name, *rest, **kw, &block)
end
end
module_function :open
end

module URI
# Allows the opening of various resources including URIs.
#
Expand All @@ -49,9 +28,7 @@ def self.open(name, *rest, &block)
(uri = URI.parse(name)).respond_to?(:open)
uri.open(*rest, &block)
else
open_uri_original_open(name, *rest, &block)
# After Kernel#open override is removed:
#super
super
end
end
end
Expand Down
12 changes: 0 additions & 12 deletions test/open-uri/test_open-uri.rb
Expand Up @@ -68,18 +68,6 @@ def teardown
@proxies.each_with_index {|k, i| ENV[k] = @old_proxies[i] }
end

def test_deprecated_kernel_open
with_http {|srv, dr, url|
srv.mount_proc("/foo200", lambda { |req, res| res.body = "foo200" } )
assert_warning(/calling URI.open via Kernel#open is deprecated, call URI.open directly/) {
open("#{url}/foo200") {|f|
assert_equal("200", f.status[0])
assert_equal("foo200", f.read)
}
}
}
end

def test_200_uri_open
with_http {|srv, dr, url|
srv.mount_proc("/urifoo200", lambda { |req, res| res.body = "urifoo200" } )
Expand Down

0 comments on commit 53862fa

Please sign in to comment.