summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-28 10:29:15 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-28 10:29:15 +0000
commita606704e84b1491ea3e490746171c4f882b683e9 (patch)
tree61dbd414743dc269d4a91f1d4f06b517ee2dd180 /test
parent89133fafe70c7a3b5d04cf2be028e1eacc6e0447 (diff)
merge revision(s) 62990:
Ignore file separator from tmpfile/tmpdir name. From: SHIBATA Hiroshi <hsbt@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@62995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/test_tempfile.rb28
-rw-r--r--test/test_tmpdir.rb17
2 files changed, 44 insertions, 1 deletions
diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb
index 21edf39776..eba139fe25 100644
--- a/test/test_tempfile.rb
+++ b/test/test_tempfile.rb
@@ -352,5 +352,31 @@ puts Tempfile.new('foo').path
f.close if f && !f.closed?
File.unlink path if 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
diff --git a/test/test_tmpdir.rb b/test/test_tmpdir.rb
index 4fc4bca4d5..c9e85aeae2 100644
--- a/test/test_tmpdir.rb
+++ b/test/test_tmpdir.rb
@@ -56,4 +56,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