Skip to content

Commit

Permalink
[ruby/tmpdir] Fix for path-like objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu authored and matzbot committed Dec 16, 2024
1 parent eef4e8a commit bf0f323
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tmpdir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def next

# Generates and yields random names to create a temporary name
def create(basename, tmpdir=nil, max_try: nil, **opts)
origdir = tmpdir
if tmpdir
origdir = tmpdir = File.path(tmpdir)
raise ArgumentError, "empty parent path" if tmpdir.empty?
else
tmpdir = tmpdir()
Expand Down
10 changes: 10 additions & 0 deletions test/test_tmpdir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ def test_mktmpdir_not_empty_parent
assert_raise(ArgumentError) do
Dir.mktmpdir("foo", "")
end

path = Struct.new(:to_path).new("")
assert_raise(ArgumentError) do
Dir.mktmpdir("foo", path)
end

Dir.mktmpdir do |d|
path = Struct.new(:to_path).new(d)
assert_operator(Dir.mktmpdir("prefix-", path), :start_with?, d + "/prefix-")
end
end

def assert_mktmpdir_traversal
Expand Down

0 comments on commit bf0f323

Please sign in to comment.