[ruby/optparse] Expand literal home paths only

Paths in environment variables should already be expanded.
The base name of the program is also not subject to expansion.

181752391c
This commit is contained in:
Nobuyoshi Nakada 2025-08-03 22:41:21 +09:00 committed by git
parent 1619afb350
commit deb0240ea0
2 changed files with 37 additions and 5 deletions

View file

@ -2047,19 +2047,21 @@ XXX
def load(filename = nil, **keywords)
unless filename
basename = File.basename($0, '.*')
return true if load(File.expand_path(basename, '~/.options'), **keywords) rescue nil
return true if load(File.expand_path("~/.options/#{basename}"), **keywords) rescue nil
basename << ".options"
return [
# XDG
ENV['XDG_CONFIG_HOME'],
'~/.config',
['~/.config', true],
*ENV['XDG_CONFIG_DIRS']&.split(File::PATH_SEPARATOR),
# Haiku
'~/config/settings',
].any? {|dir|
['~/config/settings', true],
].any? {|dir, expand|
next if !dir or dir.empty?
load(File.expand_path(basename, dir), **keywords) rescue nil
filename = File.join(dir, basename)
filename = File.expand_path(filename) if expand
load(filename, **keywords) rescue nil
}
end
begin