Skip to content

Commit

Permalink
[rubygems/rubygems] Try to use pure-ruby YAML serializer for configur…
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt authored and matzbot committed Apr 19, 2023
1 parent 628e432 commit 6f50ecf
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/rubygems/config_file.rb
Expand Up @@ -324,11 +324,11 @@ def set_api_key(host, api_key)
require "fileutils"
FileUtils.mkdir_p(dirname)

Gem.load_yaml
require "bundler/yaml_serializer"

permissions = 0o600 & (~File.umask)
File.open(credentials_path, "w", permissions) do |f|
f.write config.to_yaml
f.write Bundler::YAMLSerializer.dump(config)
end

load_api_keys # reload
Expand All @@ -344,15 +344,14 @@ def unset_api_key!
end

def load_file(filename)
Gem.load_yaml
require "bundler/yaml_serializer"

yaml_errors = [ArgumentError]
yaml_errors << Psych::SyntaxError if defined?(Psych::SyntaxError)

return {} unless filename && !filename.empty? && File.exist?(filename)

begin
content = Gem::SafeYAML.load(File.read(filename))
content = Bundler::YAMLSerializer.load(File.read(filename))
unless content.is_a? Hash
warn "Failed to load #{filename} because it doesn't contain valid YAML hash"
return {}
Expand Down Expand Up @@ -487,7 +486,7 @@ def to_yaml # :nodoc:
yaml_hash[key.to_s] = value
end

yaml_hash.to_yaml
Bundler::YAMLSerializer.dump(yaml_hash)
end

# Writes out this config file, replacing its source.
Expand Down

0 comments on commit 6f50ecf

Please sign in to comment.