diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2025-08-03 22:41:21 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2025-08-03 13:53:27 +0000 |
commit | deb0240ea06d3353fe3238d41f2534d9acc108a9 (patch) | |
tree | 055604987de06da925ca9e08b2fcac6fbf02b898 /lib/optparse.rb | |
parent | 1619afb3500bb695140df6e9dacaa901bc21920c (diff) |
[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.
https://github.com/ruby/optparse/commit/181752391c
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r-- | lib/optparse.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb index 332aea2148..23b4844b2c 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -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 |