mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
603210060c
commit
83da44790b
3 changed files with 25 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Oct 6 21:29:08 2015 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* 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@atdot.net>
|
||||
|
||||
* vm_insnhelper.c (vm_call_method0): use switch() for visibilities
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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|
|
||||
|
|
Loading…
Reference in a new issue