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

ruby-changes:39981

From: akr <ko1@a...>
Date: Tue, 6 Oct 2015 21:40:52 +0900 (JST)
Subject: [ruby-changes:39981] akr:r52062 (trunk): * lib/tmpdir.rb (Dir.tmpdir): return duplicated string to be

akr	2015-10-06 21:40:41 +0900 (Tue, 06 Oct 2015)

  New Revision: 52062

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

  Log:
    * lib/tmpdir.rb (Dir.tmpdir): return duplicated string to be
      modify safely even when $SAFE > 0.

  Modified files:
    trunk/ChangeLog
    trunk/lib/tmpdir.rb
    trunk/test/test_tmpdir.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52061)
+++ ChangeLog	(revision 52062)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct  6 21:29:08 2015  Tanaka Akira  <akr@f...>
+
+	* lib/tmpdir.rb (Dir.tmpdir): return duplicated string to be
+	  modify safely even when $SAFE > 0.
+
 Tue Oct  6 19:24:38 2015  Koichi Sasada  <ko1@a...>
 
 	* vm_insnhelper.c (vm_call_method0): use switch() for visibilities
Index: lib/tmpdir.rb
===================================================================
--- lib/tmpdir.rb	(revision 52061)
+++ lib/tmpdir.rb	(revision 52062)
@@ -21,7 +21,7 @@ class Dir https://github.com/ruby/ruby/blob/trunk/lib/tmpdir.rb#L21
 
   def self.tmpdir
     if $SAFE > 0
-      @@systmpdir
+      @@systmpdir.dup
     else
       tmp = nil
       [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'].each do |dir|
Index: test/test_tmpdir.rb
===================================================================
--- test/test_tmpdir.rb	(revision 52061)
+++ test/test_tmpdir.rb	(revision 52062)
@@ -2,6 +2,25 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/test_tmpdir.rb#L2
 require 'tmpdir'
 
 class TestTmpdir < Test::Unit::TestCase
+  def test_tmpdir_modifiable
+    tmpdir = Dir.tmpdir
+    assert_equal(false, tmpdir.frozen?)
+    tmpdir_org = tmpdir.dup
+    tmpdir << "foo"
+    assert_equal(tmpdir_org, Dir.tmpdir)
+  end
+
+  def test_tmpdir_modifiable_safe
+    Thread.new {
+      $SAFE = 1
+      tmpdir = Dir.tmpdir
+      assert_equal(false, tmpdir.frozen?)
+      tmpdir_org = tmpdir.dup
+      tmpdir << "foo"
+      assert_equal(tmpdir_org, Dir.tmpdir)
+    }.join
+  end
+
   def test_world_writable
     skip "no meaning on this platform" if /mswin|mingw/ =~ RUBY_PLATFORM
     Dir.mktmpdir do |tmpdir|

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

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