File tree Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Expand file tree Collapse file tree 2 files changed +37
-5
lines changed Original file line number Diff line number Diff line change @@ -2047,19 +2047,21 @@ def candidate(word)
2047
2047
def load ( filename = nil , **keywords )
2048
2048
unless filename
2049
2049
basename = File . basename ( $0, '.*' )
2050
- return true if load ( File . expand_path ( basename , ' ~/.options' ) , **keywords ) rescue nil
2050
+ return true if load ( File . expand_path ( " ~/.options/ #{ basename } " ) , **keywords ) rescue nil
2051
2051
basename << ".options"
2052
2052
return [
2053
2053
# XDG
2054
2054
ENV [ 'XDG_CONFIG_HOME' ] ,
2055
- '~/.config' ,
2055
+ [ '~/.config' , true ] ,
2056
2056
*ENV [ 'XDG_CONFIG_DIRS' ] &.split ( File ::PATH_SEPARATOR ) ,
2057
2057
2058
2058
# Haiku
2059
- '~/config/settings' ,
2060
- ] . any? { |dir |
2059
+ [ '~/config/settings' , true ] ,
2060
+ ] . any? { |dir , expand |
2061
2061
next if !dir or dir . empty?
2062
- load ( File . expand_path ( basename , dir ) , **keywords ) rescue nil
2062
+ filename = File . join ( dir , basename )
2063
+ filename = File . expand_path ( filename ) if expand
2064
+ load ( filename , **keywords ) rescue nil
2063
2065
}
2064
2066
end
2065
2067
begin
Original file line number Diff line number Diff line change @@ -75,6 +75,10 @@ def setup_options_home_config_settings(&block)
75
75
setup_options ( { } , "config/settings" , ".options" , &block )
76
76
end
77
77
78
+ def setup_options_home_options ( envname , &block )
79
+ setup_options ( { envname => '~/options' } , "options" , ".options" , &block )
80
+ end
81
+
78
82
def test_load_home_options
79
83
result , = setup_options_home
80
84
assert_load ( result )
@@ -145,4 +149,30 @@ def test_load_nothing
145
149
assert_load_nothing
146
150
end
147
151
end
152
+
153
+ def test_not_expand_path_basename
154
+ basename = @basename
155
+ @basename = "~"
156
+ $test_optparse_basename = "/" + @basename
157
+ alias $test_optparse_prog $0
158
+ alias $0 $test_optparse_basename
159
+ setup_options ( { 'HOME' => @tmpdir +"/~options" } , "" , "options" ) do
160
+ assert_load_nothing
161
+ end
162
+ ensure
163
+ alias $0 $test_optparse_prog
164
+ @basename = basename
165
+ end
166
+
167
+ def test_not_expand_path_xdg_config_home
168
+ setup_options_home_options ( 'XDG_CONFIG_HOME' ) do
169
+ assert_load_nothing
170
+ end
171
+ end
172
+
173
+ def test_not_expand_path_xdg_config_dirs
174
+ setup_options_home_options ( 'XDG_CONFIG_DIRS' ) do
175
+ assert_load_nothing
176
+ end
177
+ end
148
178
end
You can’t perform that action at this time.
0 commit comments