diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-05-28 19:49:10 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-05-29 07:06:46 -0700 |
commit | 2ecfb88ee50510955acd3ae9fc94a5f109e7f109 (patch) | |
tree | 61e6604cfd3425f043fbf22f491bdc6d44a4cb07 | |
parent | 0bd025ad6991f2159ef8bd596a79c89b79f5cc3e (diff) |
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]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3159
-rw-r--r-- | lib/tmpdir.rb | 2 | ||||
-rw-r--r-- | test/test_tmpdir.rb | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index c61365577e..e6cb327fc7 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -86,7 +86,7 @@ class Dir } 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 c599dcf516..50583b5ce1 100644 --- a/test/test_tmpdir.rb +++ b/test/test_tmpdir.rb @@ -52,6 +52,17 @@ class TestTmpdir < Test::Unit::TestCase } 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| |