1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]
This commit is contained in:
Jeremy Evans 2020-05-28 19:49:10 -07:00
parent 0bd025ad69
commit 2ecfb88ee5
Notes: git 2020-05-29 23:07:10 +09:00
2 changed files with 12 additions and 1 deletions

View file

@ -86,7 +86,7 @@ class Dir
}
if block_given?
begin
yield path
yield path.dup
ensure
unless base
stat = File.stat(File.dirname(path))

View file

@ -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|