From 83da44790b0a4099d7ea54bdeee84e605f940cd1 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 6 Oct 2015 12:40:41 +0000 Subject: [PATCH] * 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 --- ChangeLog | 5 +++++ lib/tmpdir.rb | 2 +- test/test_tmpdir.rb | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fb22b6f325..501c1a98f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Oct 6 21:29:08 2015 Tanaka Akira + + * 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 * 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|