File tree Expand file tree Collapse file tree 2 files changed +38
-5
lines changed Expand file tree Collapse file tree 2 files changed +38
-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 @@ -69,6 +69,11 @@ def setup_options_home_config_settings(&block)
69
69
setup_options ( { 'HOME' => @tmpdir } , "config/settings" , ".options" , &block )
70
70
end
71
71
72
+ def setup_options_home_options ( envs , &block )
73
+ envs . update ( { 'HOME' => @tmpdir } )
74
+ setup_options ( envs , "options" , ".options" , &block )
75
+ end
76
+
72
77
def test_load_home_options
73
78
result , = setup_options_home
74
79
assert_load ( result )
@@ -138,4 +143,30 @@ def test_load_nothing
138
143
assert !new_parser . load
139
144
assert_nil @result
140
145
end
146
+
147
+ def test_not_expand_path_basename
148
+ basename = @basename
149
+ @basename = "~"
150
+ $test_optparse_basename = "/" + @basename
151
+ alias $test_optparse_prog $0
152
+ alias $0 $test_optparse_basename
153
+ setup_options ( { 'HOME' => @tmpdir +"/~options" } , "" , "options" ) do
154
+ test_load_nothing
155
+ end
156
+ ensure
157
+ alias $0 $test_optparse_prog
158
+ @basename = basename
159
+ end
160
+
161
+ def test_not_expand_path_xdg_config_home
162
+ setup_options_home_options ( { 'XDG_CONFIG_HOME' => '~/options' } ) do
163
+ test_load_nothing
164
+ end
165
+ end
166
+
167
+ def test_not_expand_path_xdg_config_dirs
168
+ setup_options_home_options ( { 'XDG_CONFIG_DIRS' => '~/options' } ) do
169
+ test_load_nothing
170
+ end
171
+ end
141
172
end
You can’t perform that action at this time.
0 commit comments