[ruby/tmpdir] Fix for path-like objects
Fix https://github.com/ruby/tmpdir/pull/37 https://github.com/ruby/tmpdir/commit/a8ceafae7d
This commit is contained in:
parent
eef4e8a2c8
commit
bf0f323907
@ -149,8 +149,8 @@ class Dir
|
|||||||
|
|
||||||
# Generates and yields random names to create a temporary name
|
# Generates and yields random names to create a temporary name
|
||||||
def create(basename, tmpdir=nil, max_try: nil, **opts)
|
def create(basename, tmpdir=nil, max_try: nil, **opts)
|
||||||
origdir = tmpdir
|
|
||||||
if tmpdir
|
if tmpdir
|
||||||
|
origdir = tmpdir = File.path(tmpdir)
|
||||||
raise ArgumentError, "empty parent path" if tmpdir.empty?
|
raise ArgumentError, "empty parent path" if tmpdir.empty?
|
||||||
else
|
else
|
||||||
tmpdir = tmpdir()
|
tmpdir = tmpdir()
|
||||||
|
@ -108,6 +108,16 @@ class TestTmpdir < Test::Unit::TestCase
|
|||||||
assert_raise(ArgumentError) do
|
assert_raise(ArgumentError) do
|
||||||
Dir.mktmpdir("foo", "")
|
Dir.mktmpdir("foo", "")
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def assert_mktmpdir_traversal
|
def assert_mktmpdir_traversal
|
||||||
|
Loading…
x
Reference in New Issue
Block a user