Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handle in ill formated .gemrc file better

  • Loading branch information...
commit 1bc83dfb45bf258b93b82b02999bd1f850bc2b7d 1 parent 024e06b
@evanphx evanphx authored
View
7 lib/rubygems/config_file.rb
@@ -249,7 +249,12 @@ def load_file(filename)
return {} unless filename and File.exist? filename
begin
- return YAML.load(File.read(filename))
+ content = YAML.load(File.read(filename))
+ unless content.kind_of? Hash
+ warn "Failed to load #{config_file_name} because it doesn't contain valid YAML hash"
+ return {}
+ end
+ return content
rescue ArgumentError
warn "Failed to load #{config_file_name}"
rescue Errno::EACCES
View
12 test/rubygems/test_gem_config_file.rb
@@ -317,6 +317,18 @@ def test_save_credentials_file_with_strict_permissions
assert_equal mode, File.stat(@cfg.credentials_path).mode unless win_platform?
end
+ def test_ignore_invalid_config_file
+ File.open @temp_conf, 'w' do |fp|
+ fp.puts "some-non-yaml-hash-string"
+ end
+
+ # Avoid writing stuff to output when running tests
+ Gem::ConfigFile.class_eval { def warn(args); end }
+
+ # This should not raise exception
+ util_config_file
+ end
+
def util_config_file(args = @cfg_args)
@cfg = Gem::ConfigFile.new args
end
Please sign in to comment.
Something went wrong with that request. Please try again.