diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-06 12:40:41 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-06 12:40:41 +0000 |
commit | 83da44790b0a4099d7ea54bdeee84e605f940cd1 (patch) | |
tree | 433c68372259214769f2a3a3f48de4f6908df100 | |
parent | 603210060c08b2693bc9c597cf4200bf51efd362 (diff) |
* lib/tmpdir.rb (Dir.tmpdir): return duplicated string to be
modify safely even when $SAFE > 0.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/tmpdir.rb | 2 | ||||
-rw-r--r-- | test/test_tmpdir.rb | 19 |
3 files changed, 25 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Tue Oct 6 21:29:08 2015 Tanaka Akira <[email protected]> + + * 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 <[email protected]> * vm_insnhelper.c (vm_call_method0): use switch() for visibilities diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index adbe404146..3c6c00bc8e 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -21,7 +21,7 @@ class Dir def self.tmpdir if $SAFE > 0 - @@systmpdir + @@systmpdir.dup else tmp = nil [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'].each do |dir| diff --git a/test/test_tmpdir.rb b/test/test_tmpdir.rb index 62b4abfa1a..842b2ded90 100644 --- a/test/test_tmpdir.rb +++ b/test/test_tmpdir.rb @@ -2,6 +2,25 @@ require 'test/unit' 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| |