Skip to content

Commit f636d01

Browse files
committed
Make URI.open pass keywords
Fixes [Bug #19238]
1 parent c56f582 commit f636d01

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/open-uri.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def self.open(name, *rest, &block)
3131
super
3232
end
3333
end
34+
singleton_class.send(:ruby2_keywords, :open) if respond_to?(:ruby2_keywords, true)
3435
end
3536

3637
# OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP.

test/open-uri/test_open-uri.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ def test_invalid_option
172172
assert_raise(ArgumentError) { URI.open("http://127.0.0.1/", :invalid_option=>true) {} }
173173
end
174174

175+
def test_pass_keywords
176+
require 'tempfile'
177+
t = Tempfile.new
178+
assert_kind_of File, URI.open(Tempfile.new.path, mode: 0666)
179+
180+
o = Object.new
181+
def o.open(foo: ) foo end
182+
assert_equal 1, URI.open(o, foo: 1)
183+
end
184+
175185
def test_mode
176186
with_http {|srv, dr, url|
177187
srv.mount_proc("/mode", lambda { |req, res| res.body = "mode" } )

0 commit comments

Comments
 (0)