Skip to content

Commit 1b5fc5b

Browse files
hsbtdeivid-rodriguez
authored andcommitted
Merge pull request #7543 from rubygems/allow-string-keys
Allow string keys with gemrc (cherry picked from commit bdb1468)
1 parent 9904eca commit 1b5fc5b

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

lib/rubygems/config_file.rb

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,33 @@ def initialize(args)
202202
@hash = @hash.merge environment_config
203203
end
204204

205+
@hash.transform_keys! do |k|
206+
# gemhome and gempath are not working with symbol keys
207+
if %w[backtrace bulk_threshold verbose update_sources cert_expiration_length_days
208+
install_extension_in_lib ipv4_fallback_enabled sources disable_default_gem_server
209+
ssl_verify_mode ssl_ca_cert ssl_client_cert].include?(k)
210+
k.to_sym
211+
else
212+
k
213+
end
214+
end
215+
205216
# HACK: these override command-line args, which is bad
206217
@backtrace = @hash[:backtrace] if @hash.key? :backtrace
207218
@bulk_threshold = @hash[:bulk_threshold] if @hash.key? :bulk_threshold
208-
@home = @hash[:gemhome] if @hash.key? :gemhome
209-
@path = @hash[:gempath] if @hash.key? :gempath
210-
@update_sources = @hash[:update_sources] if @hash.key? :update_sources
211219
@verbose = @hash[:verbose] if @hash.key? :verbose
212-
@disable_default_gem_server = @hash[:disable_default_gem_server] if @hash.key? :disable_default_gem_server
213-
@sources = @hash[:sources] if @hash.key? :sources
220+
@update_sources = @hash[:update_sources] if @hash.key? :update_sources
221+
# TODO: We should handle concurrent_downloads same as other options
214222
@cert_expiration_length_days = @hash[:cert_expiration_length_days] if @hash.key? :cert_expiration_length_days
215223
@ipv4_fallback_enabled = @hash[:ipv4_fallback_enabled] if @hash.key? :ipv4_fallback_enabled
216224

217-
@ssl_verify_mode = @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode
218-
@ssl_ca_cert = @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert
219-
@ssl_client_cert = @hash[:ssl_client_cert] if @hash.key? :ssl_client_cert
225+
@home = @hash[:gemhome] if @hash.key? :gemhome
226+
@path = @hash[:gempath] if @hash.key? :gempath
227+
@sources = @hash[:sources] if @hash.key? :sources
228+
@disable_default_gem_server = @hash[:disable_default_gem_server] if @hash.key? :disable_default_gem_server
229+
@ssl_verify_mode = @hash[:ssl_verify_mode] if @hash.key? :ssl_verify_mode
230+
@ssl_ca_cert = @hash[:ssl_ca_cert] if @hash.key? :ssl_ca_cert
231+
@ssl_client_cert = @hash[:ssl_client_cert] if @hash.key? :ssl_client_cert
220232

221233
@api_keys = nil
222234
@rubygems_api_key = nil

test/rubygems/test_gem_config_file.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,16 @@ def test_ignore_invalid_config_file
485485
end
486486
end
487487

488+
def test_accept_string_key
489+
File.open @temp_conf, "w" do |fp|
490+
fp.puts "verbose: false"
491+
end
492+
493+
util_config_file
494+
495+
assert_equal false, @cfg.verbose
496+
end
497+
488498
def test_load_ssl_verify_mode_from_config
489499
File.open @temp_conf, "w" do |fp|
490500
fp.puts ":ssl_verify_mode: 1"

0 commit comments

Comments
 (0)