From 814f52a9ebd035ec6e20641c602fa42f64b5dbe0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 1 May 2023 01:13:57 +0900 Subject: [Bug #19624] Hide internal IO for backquote --- io.c | 1 + test/ruby/test_system.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/io.c b/io.c index fb822f0f58..17a2d30c71 100644 --- a/io.c +++ b/io.c @@ -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; diff --git a/test/ruby/test_system.rb b/test/ruby/test_system.rb index 31c9cd7654..3fcdaa6aad 100644 --- a/test/ruby/test_system.rb +++ b/test/ruby/test_system.rb @@ -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 -- cgit v1.2.1