[ruby/reline] Treat home dir correctly

https://github.com/ruby/reline/commit/9b1327d2f4
This commit is contained in:
aycabta 2020-04-24 03:10:41 +09:00
Родитель 81b0b79197
Коммит 9fb20711fd
2 изменённых файлов: 5 добавлений и 4 удалений

Просмотреть файл

@ -91,8 +91,8 @@ class Reline::Config
# In the XDG Specification, if ~/.config/readline/inputrc exists, then
# ~/.inputrc should not be read, but for compatibility with GNU Readline,
# if ~/.inputrc exists, then it is given priority.
path = File.expand_path('~/.inputrc')
return path if File.exist?(path)
home_rc_path = File.expand_path('~/.inputrc')
return home_rc_path if File.exist?(home_rc_path)
case ENV['XDG_CONFIG_HOME']
when nil, ''
@ -102,6 +102,8 @@ class Reline::Config
path = File.expand_path("#{ENV['XDG_CONFIG_HOME']}/readline/inputrc")
return path if File.exist?(path)
end
return home_rc_path
end
def read(file = nil)

Просмотреть файл

@ -227,12 +227,11 @@ class Reline::Config::Test < Reline::TestCase
def test_xdg_config_home
home_backup = ENV['HOME']
xdg_config_home_backup = ENV['XDG_CONFIG_HOME']
nonexistence_dir = '/the_nonexistence_dir!!!!!!'
xdg_config_home = File.expand_path("#{@tmpdir}/.config/example_dir")
expected = File.expand_path("#{xdg_config_home}/readline/inputrc")
FileUtils.mkdir_p(File.dirname(expected))
FileUtils.touch(expected)
ENV['HOME'] = nonexistence_dir
ENV['HOME'] = @tmpdir
ENV['XDG_CONFIG_HOME'] = xdg_config_home
assert_equal expected, @config.inputrc_path
FileUtils.rm(expected)