[Bug #19624] Hide internal IO for backquote

This commit is contained in:
Nobuyoshi Nakada 2023-05-01 01:13:57 +09:00
parent b82c06a711
commit 814f52a9eb
Notes: git 2023-04-30 20:11:03 +00:00
2 changed files with 14 additions and 0 deletions

1
io.c
View File

@ -10497,6 +10497,7 @@ rb_f_backquote(VALUE obj, VALUE str)
if (NIL_P(port)) return rb_str_new(0,0);
GetOpenFile(port, fptr);
rb_obj_hide(port);
result = read_all(fptr, remain_size(fptr), Qnil);
rb_io_close(port);
RFILE(port)->fptr = NULL;

View File

@ -146,6 +146,19 @@ class TestSystem < Test::Unit::TestCase
end
end
def test_system_closed
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
ios = []
ObjectSpace.each_object(IO) {|io| ios << io}
`echo`
ObjectSpace.each_object(IO) do |io|
next if ios.include?(io)
assert_nothing_raised {io.close}
end
end;
end
def test_empty_evstr
assert_equal("", eval('"#{}"', nil, __FILE__, __LINE__), "[ruby-dev:25113]")
end