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:
parent
0bd025ad69
commit
2ecfb88ee5
Notes:
git
2020-05-29 23:07:10 +09:00
2 changed files with 12 additions and 1 deletions
|
|
@ -86,7 +86,7 @@ class Dir
|
||||||
}
|
}
|
||||||
if block_given?
|
if block_given?
|
||||||
begin
|
begin
|
||||||
yield path
|
yield path.dup
|
||||||
ensure
|
ensure
|
||||||
unless base
|
unless base
|
||||||
stat = File.stat(File.dirname(path))
|
stat = File.stat(File.dirname(path))
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,17 @@ class TestTmpdir < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
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
|
def test_mktmpdir_traversal
|
||||||
assert_mktmpdir_traversal do |traversal_path|
|
assert_mktmpdir_traversal do |traversal_path|
|
||||||
Dir.mktmpdir(traversal_path + 'foo') do |actual|
|
Dir.mktmpdir(traversal_path + 'foo') do |actual|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue