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

ruby-changes:74246

From: Nobuyoshi <ko1@a...>
Date: Tue, 25 Oct 2022 16:54:58 +0900 (JST)
Subject: [ruby-changes:74246] 114e71d062 (master): [ruby/tmpdir] Ignore empty environment variables

https://git.ruby-lang.org/ruby.git/commit/?id=114e71d062

From 114e71d06280f9c57b9859ee4405ae89a989ddb6 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 25 Oct 2022 16:39:12 +0900
Subject: [ruby/tmpdir] Ignore empty environment variables

Fixes https://github.com/ruby/tmpdir/pull/17

https://github.com/ruby/tmpdir/commit/a79c727a5d
---
 lib/tmpdir.rb       |  6 ++++--
 test/test_tmpdir.rb | 12 ++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
index 95d4ca3fce..55920a4a74 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -19,8 +19,10 @@ class Dir https://github.com/ruby/ruby/blob/trunk/lib/tmpdir.rb#L19
   # 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
diff --git a/test/test_tmpdir.rb b/test/test_tmpdir.rb
index 0be2176bd9..1adb6a70b7 100644
--- a/test/test_tmpdir.rb
+++ b/test/test_tmpdir.rb
@@ -47,6 +47,18 @@ class TestTmpdir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_tmpdir.rb#L47
     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
-- 
cgit v1.2.3


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

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