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

ruby-changes:60943

From: Nobuyoshi <ko1@a...>
Date: Wed, 29 Apr 2020 19:14:35 +0900 (JST)
Subject: [ruby-changes:60943] 0ac5009165 (master): [ruby/reline] Ignore non-absolute XDG_CONFIG_HOME

https://git.ruby-lang.org/ruby.git/commit/?id=0ac5009165

From 0ac5009165e0d743b82ac673d4eb98e871f4ea0b Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 24 Apr 2020 17:54:54 +0900
Subject: [ruby/reline] Ignore non-absolute XDG_CONFIG_HOME

https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
> All paths set in these environment variables must be absolute.
> If an implementation encounters a relative path in any of these
> variables it should consider the path invalid and ignore it.

https://github.com/ruby/reline/commit/45af6eea77

diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index b299bcc..fd761ae 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -94,15 +94,16 @@ class Reline::Config https://github.com/ruby/ruby/blob/trunk/lib/reline/config.rb#L94
     home_rc_path = File.expand_path('~/.inputrc')
     return home_rc_path if File.exist?(home_rc_path)
 
-    case ENV['XDG_CONFIG_HOME']
+    case path = ENV['XDG_CONFIG_HOME']
     when nil, ''
-      path = File.expand_path('~/.config/readline/inputrc')
-      return path if File.exist?(path)
     else
-      path = File.expand_path("#{ENV['XDG_CONFIG_HOME']}/readline/inputrc")
-      return path if File.exist?(path)
+      path = File.join(path, 'readline/inputrc')
+      return path if File.exist?(path) and path == File.expand_path(path)
     end
 
+    path = File.expand_path('~/.config/readline/inputrc')
+    return path if File.exist?(path)
+
     return home_rc_path
   end
 
diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb
index bf980a2..d24d4e8 100644
--- a/test/reline/test_config.rb
+++ b/test/reline/test_config.rb
@@ -213,6 +213,7 @@ class Reline::Config::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L213
     assert_nothing_raised do
       @config.read
     end
+  ensure
     ENV['INPUTRC'] = inputrc_backup
   end
 
@@ -221,6 +222,7 @@ class Reline::Config::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L222
     expected = "#{@tmpdir}/abcde"
     ENV['INPUTRC'] = expected
     assert_equal expected, @config.inputrc_path
+  ensure
     ENV['INPUTRC'] = inputrc_backup
   end
 
@@ -234,6 +236,7 @@ class Reline::Config::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L236
     ENV['HOME'] = @tmpdir
     ENV['XDG_CONFIG_HOME'] = xdg_config_home
     assert_equal expected, @config.inputrc_path
+  ensure
     FileUtils.rm(expected)
     ENV['XDG_CONFIG_HOME'] = xdg_config_home_backup
     ENV['HOME'] = home_backup
@@ -248,6 +251,28 @@ class Reline::Config::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L251
     FileUtils.mkdir_p(File.dirname(expected))
     FileUtils.touch(expected)
     assert_equal expected, @config.inputrc_path
+  ensure
+    FileUtils.rm(expected)
+    ENV['XDG_CONFIG_HOME'] = xdg_config_home_backup
+    ENV['HOME'] = home_backup
+  end
+
+  def test_relative_xdg_config_home
+    home_backup = ENV['HOME']
+    xdg_config_home_backup = ENV['XDG_CONFIG_HOME']
+    ENV['HOME'] = @tmpdir
+    expected = File.expand_path('~/.config/readline/inputrc')
+    FileUtils.mkdir_p(File.dirname(expected))
+    FileUtils.touch(expected)
+    result = Dir.chdir(@tmpdir) do
+      xdg_config_home = ".config/example_dir"
+      ENV['XDG_CONFIG_HOME'] = xdg_config_home
+      inputrc = "#{xdg_config_home}/readline/inputrc"
+      FileUtils.mkdir_p(File.dirname(inputrc))
+      FileUtils.touch(inputrc)
+      @config.inputrc_path
+    end
+    assert_equal expected, result
     FileUtils.rm(expected)
     ENV['XDG_CONFIG_HOME'] = xdg_config_home_backup
     ENV['HOME'] = home_backup
-- 
cgit v0.10.2


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

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