Skip to content

Commit b08fec4

Browse files
jeremyevanshsbt
authored andcommitted
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]
1 parent 4d2b260 commit b08fec4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/tmpdir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def self.mktmpdir(prefix_suffix=nil, *rest, **options)
8686
}
8787
if block_given?
8888
begin
89-
yield path
89+
yield path.dup
9090
ensure
9191
unless base
9292
stat = File.stat(File.dirname(path))

test/test_tmpdir.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ def test_mktmpdir_nil
5252
}
5353
end
5454

55+
def test_mktmpdir_mutate
56+
bug16918 = '[ruby-core:98563]'
57+
assert_nothing_raised(bug16918) do
58+
assert_mktmpdir_traversal do |traversal_path|
59+
Dir.mktmpdir(traversal_path + 'foo') do |actual|
60+
actual << "foo"
61+
end
62+
end
63+
end
64+
end
65+
5566
def test_mktmpdir_traversal
5667
assert_mktmpdir_traversal do |traversal_path|
5768
Dir.mktmpdir(traversal_path + 'foo') do |actual|

0 commit comments

Comments
 (0)