[前][次][番号順一覧][スレッド一覧]

ruby-changes:50792

From: nagachika <ko1@a...>
Date: Wed, 28 Mar 2018 19:52:39 +0900 (JST)
Subject: [ruby-changes:50792] nagachika:r62998 (ruby_2_4): merge revision(s) 62990:

nagachika	2018-03-28 19:52:33 +0900 (Wed, 28 Mar 2018)

  New Revision: 62998

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62998

  Log:
    merge revision(s) 62990:
    
    Ignore file separator from tmpfile/tmpdir name.
    
    From: SHIBATA Hiroshi <hsbt@r...>

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/lib/tmpdir.rb
    branches/ruby_2_4/test/test_tempfile.rb
    branches/ruby_2_4/test/test_tmpdir.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 62997)
+++ ruby_2_4/version.h	(revision 62998)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.4"
 #define RUBY_RELEASE_DATE "2018-03-28"
-#define RUBY_PATCHLEVEL 289
+#define RUBY_PATCHLEVEL 290
 
 #define RUBY_RELEASE_YEAR 2018
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_4/lib/tmpdir.rb
===================================================================
--- ruby_2_4/lib/tmpdir.rb	(revision 62997)
+++ ruby_2_4/lib/tmpdir.rb	(revision 62998)
@@ -109,8 +109,10 @@ class Dir https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/tmpdir.rb#L109
     def make_tmpname((prefix, suffix), n)
       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}")
       t = Time.now.strftime("%Y%m%d")
       path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}".dup
       path << "-#{n}" if n
Index: ruby_2_4/test/test_tmpdir.rb
===================================================================
--- ruby_2_4/test/test_tmpdir.rb	(revision 62997)
+++ ruby_2_4/test/test_tmpdir.rb	(revision 62998)
@@ -56,4 +56,21 @@ class TestTmpdir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/test_tmpdir.rb#L56
       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
Index: ruby_2_4/test/test_tempfile.rb
===================================================================
--- ruby_2_4/test/test_tempfile.rb	(revision 62997)
+++ ruby_2_4/test/test_tempfile.rb	(revision 62998)
@@ -365,5 +365,31 @@ puts Tempfile.new('foo').path https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/test_tempfile.rb#L365
     }
     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_4
===================================================================
--- ruby_2_4	(revision 62997)
+++ ruby_2_4	(revision 62998)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r62990

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]