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
Родитель 0bd025ad69
Коммит 2ecfb88ee5
2 изменённых файлов: 12 добавлений и 1 удалений

Просмотреть файл

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

Просмотреть файл

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