ruby-changes:50780
From: naruse <ko1@a...>
Date: Wed, 28 Mar 2018 18:26:06 +0900 (JST)
Subject: [ruby-changes:50780] naruse:r62971 (ruby_2_5): Remove directory separators
naruse 2018-03-28 18:26:00 +0900 (Wed, 28 Mar 2018) New Revision: 62971 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62971 Log: Remove directory separators Modified files: branches/ruby_2_5/lib/tmpdir.rb branches/ruby_2_5/test/test_tempfile.rb branches/ruby_2_5/test/test_tmpdir.rb Index: ruby_2_5/test/test_tmpdir.rb =================================================================== --- ruby_2_5/test/test_tmpdir.rb (revision 62970) +++ ruby_2_5/test/test_tmpdir.rb (revision 62971) @@ -56,4 +56,20 @@ class TestTmpdir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/test_tmpdir.rb#L56 assert_kind_of(String, d) } end + + TRAVERSAL_PATH = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/' + + 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 Index: ruby_2_5/test/test_tempfile.rb =================================================================== --- ruby_2_5/test/test_tempfile.rb (revision 62970) +++ ruby_2_5/test/test_tempfile.rb (revision 62971) @@ -371,5 +371,31 @@ puts Tempfile.new('foo').path https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/test_tempfile.rb#L371 } 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 Index: ruby_2_5/lib/tmpdir.rb =================================================================== --- ruby_2_5/lib/tmpdir.rb (revision 62970) +++ ruby_2_5/lib/tmpdir.rb (revision 62971) @@ -114,10 +114,12 @@ class Dir https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/tmpdir.rb#L114 end n = nil prefix, suffix = basename + prefix = prefix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}") prefix = (String.try_convert(prefix) or raise ArgumentError, "unexpected prefix: #{prefix.inspect}") 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)}"\ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/