ruby-changes:61419
From: Jeremy <ko1@a...>
Date: Fri, 29 May 2020 23:07:04 +0900 (JST)
Subject: [ruby-changes:61419] 2ecfb88ee5 (master): Correctly remove temporary directory if path yielded is mutated
https://git.ruby-lang.org/ruby.git/commit/?id=2ecfb88ee5 From 2ecfb88ee50510955acd3ae9fc94a5f109e7f109 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Thu, 28 May 2020 19:49:10 -0700 Subject: Correctly remove temporary directory if path yielded is mutated Another approach would be to freeze the string, but that could cause backwards compatibility issues. Fixes [Bug #16918] diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index c613655..e6cb327 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -86,7 +86,7 @@ class Dir https://github.com/ruby/ruby/blob/trunk/lib/tmpdir.rb#L86 } if block_given? begin - yield path + yield path.dup ensure unless base stat = File.stat(File.dirname(path)) diff --git a/test/test_tmpdir.rb b/test/test_tmpdir.rb index c599dcf..50583b5 100644 --- a/test/test_tmpdir.rb +++ b/test/test_tmpdir.rb @@ -52,6 +52,17 @@ class TestTmpdir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_tmpdir.rb#L52 } end + def test_mktmpdir_mutate + bug16918 = '[ruby-core:98563]' + assert_nothing_raised(bug16918) do + assert_mktmpdir_traversal do |traversal_path| + Dir.mktmpdir(traversal_path + 'foo') do |actual| + actual << "foo" + end + end + end + end + def test_mktmpdir_traversal assert_mktmpdir_traversal do |traversal_path| Dir.mktmpdir(traversal_path + 'foo') do |actual| -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/