diff options
-rw-r--r-- | io.c | 2 | ||||
-rw-r--r-- | test/ruby/test_argf.rb | 15 |
2 files changed, 16 insertions, 1 deletions
@@ -12988,7 +12988,7 @@ opt_i_set(VALUE val, ID id, VALUE *var) void ruby_set_inplace_mode(const char *suffix) { - ARGF.inplace = !suffix ? Qfalse : !*suffix ? Qnil : rb_fstring_cstr(suffix); + ARGF.inplace = !suffix ? Qfalse : !*suffix ? Qnil : rb_str_new(suffix, strlen(suffix)); } /* diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index 277fa368f5..4734d5b3ae 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -387,6 +387,21 @@ class TestArgf < Test::Unit::TestCase assert_equal("foo", File.read(name+suffix)) end + def test_inplace_bug_17117 + assert_in_out_err(["-", @t1.path], "#{<<~"{#"}#{<<~'};'}") + {# + #!/usr/bin/ruby -pi.bak + BEGIN { + GC.start + arr = [] + 1000000.times { |x| arr << "fooo#{x}" } + } + puts "hello" + }; + assert_equal("hello\n1\nhello\n2\n", File.read(@t1.path)) + assert_equal("1\n2\n", File.read("#{@t1.path}.bak")) + end + def test_encoding ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# |