mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Ignore file separator from tmpfile/tmpdir name.
From: SHIBATA Hiroshi <hsbt@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bd5661a3cb
commit
10b96900b9
3 changed files with 46 additions and 1 deletions
|
@ -116,8 +116,10 @@ class Dir
|
|||
prefix, suffix = basename
|
||||
prefix = (String.try_convert(prefix) or
|
||||
raise ArgumentError, "unexpected prefix: #{prefix.inspect}")
|
||||
prefix = prefix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
|
||||
suffix &&= (String.try_convert(suffix) or
|
||||
raise ArgumentError, "unexpected suffix: #{suffix.inspect}")
|
||||
suffix &&= suffix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
|
||||
begin
|
||||
t = Time.now.strftime("%Y%m%d")
|
||||
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"\
|
||||
|
|
|
@ -373,5 +373,31 @@ puts Tempfile.new('foo').path
|
|||
}
|
||||
assert_file.not_exist?(path)
|
||||
end
|
||||
end
|
||||
|
||||
TRAVERSAL_PATH = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/'
|
||||
|
||||
def test_open_traversal_dir
|
||||
expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
||||
t = Tempfile.open([TRAVERSAL_PATH, 'foo'])
|
||||
actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
||||
assert_equal expect, actual
|
||||
ensure
|
||||
t.close!
|
||||
end
|
||||
|
||||
def test_new_traversal_dir
|
||||
expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
||||
t = Tempfile.new(TRAVERSAL_PATH + 'foo')
|
||||
actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
||||
assert_equal expect, actual
|
||||
ensure
|
||||
t.close!
|
||||
end
|
||||
|
||||
def test_create_traversal_dir
|
||||
expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
||||
Tempfile.create(TRAVERSAL_PATH + 'foo')
|
||||
actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
||||
assert_equal expect, actual
|
||||
end
|
||||
end
|
||||
|
|
|
@ -58,4 +58,21 @@ class TestTmpdir < Test::Unit::TestCase
|
|||
assert_kind_of(String, d)
|
||||
}
|
||||
end
|
||||
|
||||
TRAVERSAL_PATH = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/'
|
||||
TRAVERSAL_PATH.delete!(':') if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||
|
||||
def test_mktmpdir_traversal
|
||||
expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
||||
Dir.mktmpdir(TRAVERSAL_PATH + 'foo')
|
||||
actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
||||
assert_equal expect, actual
|
||||
end
|
||||
|
||||
def test_mktmpdir_traversal_array
|
||||
expect = Dir.glob(TRAVERSAL_PATH + '*').count
|
||||
Dir.mktmpdir([TRAVERSAL_PATH, 'foo'])
|
||||
actual = Dir.glob(TRAVERSAL_PATH + '*').count
|
||||
assert_equal expect, actual
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue