Skip to content

Commit 87000a0

Browse files
committed
[GR-31842] Fix delegation in open-uri
PullRequest: truffleruby/2688
2 parents 3e2c2ee + 5bf0add commit 87000a0

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/mri/open-uri.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@ class << self
1010
alias open_uri_original_open open # :nodoc:
1111
end
1212

13-
def open(name, *rest, **kw, &block) # :nodoc:
13+
def open(name, *rest, &block) # :nodoc:
1414
if (name.respond_to?(:open) && !name.respond_to?(:to_path)) ||
1515
(name.respond_to?(:to_str) &&
1616
%r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
1717
(uri = URI.parse(name)).respond_to?(:open))
1818
warn('calling URI.open via Kernel#open is deprecated, call URI.open directly or use URI#open', uplevel: 1)
19-
URI.open(name, *rest, **kw, &block)
19+
URI.open(name, *rest, &block)
2020
else
21-
open_uri_original_open(name, *rest, **kw, &block)
21+
open_uri_original_open(name, *rest, &block)
2222
end
2323
end
2424
module_function :open
25+
ruby2_keywords :open
26+
class << self
27+
ruby2_keywords :open
28+
end
2529
end
2630

2731
module URI

spec/ruby/core/kernel/open_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
require_relative 'fixtures/classes'
33

44
describe "Kernel#open" do
5-
65
before :each do
76
@name = tmp("kernel_open.txt")
87
@content = "This is a test"
@@ -137,6 +136,18 @@
137136
it "accepts nil for mode and permission" do
138137
open(@name, nil, nil) { |f| f.gets }.should == @content
139138
end
139+
140+
ruby_version_is ""..."3.0" do
141+
it "works correctly when redefined by open-uri" do
142+
code = <<~RUBY
143+
require 'open-uri'
144+
obj = Object.new
145+
def obj.to_open; self; end
146+
p open(obj) == obj
147+
RUBY
148+
ruby_exe(code, args: "2>&1").should == "true\n"
149+
end
150+
end
140151
end
141152

142153
describe "Kernel.open" do

spec/tags/core/kernel/open_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
slow:Kernel#open works correctly when redefined by open-uri

0 commit comments

Comments
 (0)