mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/tmpdir] Ignore empty environment variables
Fixes https://github.com/ruby/tmpdir/pull/17 https://github.com/ruby/tmpdir/commit/a79c727a5d
This commit is contained in:
parent
883d9c305f
commit
114e71d062
2 changed files with 16 additions and 2 deletions
|
@ -19,8 +19,10 @@ class Dir
|
|||
# Returns the operating system's temporary file path.
|
||||
|
||||
def self.tmpdir
|
||||
['TMPDIR', 'TMP', 'TEMP', ['system temporary path', @@systmpdir], ['/tmp']*2, ['.']*2].find do |name, dir = ENV[name]|
|
||||
next if !dir
|
||||
['TMPDIR', 'TMP', 'TEMP', ['system temporary path', @@systmpdir], ['/tmp']*2, ['.']*2].find do |name, dir|
|
||||
unless dir
|
||||
next if !(dir = ENV[name]) or dir.empty?
|
||||
end
|
||||
dir = File.expand_path(dir)
|
||||
stat = File.stat(dir) rescue next
|
||||
case
|
||||
|
|
|
@ -47,6 +47,18 @@ class TestTmpdir < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_tmpdir_not_empty_parent
|
||||
Dir.mktmpdir do |tmpdir|
|
||||
envs = %w[TMPDIR TMP TEMP]
|
||||
oldenv = envs.each_with_object({}) {|v, h| h[v] = ENV.delete(v)}
|
||||
ENV[envs[0]] = ""
|
||||
ENV[envs[1]] = tmpdir
|
||||
assert_equal(tmpdir, Dir.tmpdir)
|
||||
ensure
|
||||
ENV.update(oldenv)
|
||||
end
|
||||
end
|
||||
|
||||
def test_no_homedir
|
||||
bug7547 = '[ruby-core:50793]'
|
||||
home, ENV["HOME"] = ENV["HOME"], nil
|
||||
|
|
Loading…
Reference in a new issue