[ruby/open-uri] Make URI.open pass keywords

Fixes [Bug #19238]

https://github.com/ruby/open-uri/commit/f636d01b85
This commit is contained in:
Jeremy Evans 2023-05-09 20:11:53 -07:00 committed by git
parent 544488f114
commit 43c2c1ed48
2 changed files with 11 additions and 0 deletions

View File

@ -31,6 +31,7 @@ module URI
super
end
end
singleton_class.send(:ruby2_keywords, :open) if respond_to?(:ruby2_keywords, true)
end
# OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP.

View File

@ -172,6 +172,16 @@ class TestOpenURI < Test::Unit::TestCase
assert_raise(ArgumentError) { URI.open("http://127.0.0.1/", :invalid_option=>true) {} }
end
def test_pass_keywords
require 'tempfile'
t = Tempfile.new
assert_kind_of File, URI.open(Tempfile.new.path, mode: 0666)
o = Object.new
def o.open(foo: ) foo end
assert_equal 1, URI.open(o, foo: 1)
end
def test_mode
with_http {|srv, dr, url|
srv.mount_proc("/mode", lambda { |req, res| res.body = "mode" } )