diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 1139eab503..8c69e81490 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -461,7 +461,7 @@ module Bundler new_k = k.gsub("-", "___") end - config[new_k] = v + config[new_k] = v.to_s config end end diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 9e56a944bb..09e77ab449 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -58,7 +58,7 @@ module Bundler str.split(/\r?\n/).each do |line| if match = HASH_REGEX.match(line) indent, key, quote, val = match.captures - key = convert_to_backward_compatible_key(key) if key.match?(/__/) + key = convert_to_backward_compatible_key(key) key = key[1..-1].to_sym if key.start_with?(":") depth = indent.scan(/ /).length if quote.empty? && val.empty? @@ -77,24 +77,9 @@ module Bundler last_hash[last_empty_key].push(convert_to_ruby_value(val)) end end - deep_transform_values_with_empty_hash!(res) res end - def deep_transform_values_with_empty_hash!(hash) - hash.transform_values! do |v| - if v.is_a?(Hash) - if v.empty? - nil - else - deep_transform_values_with_empty_hash!(v) - end - else - v - end - end - end - def convert_to_ruby_value(val) if val.match?(/\A:(.*)\Z/) val[1..-1].to_sym @@ -102,8 +87,6 @@ module Bundler val.to_i elsif val.match?(/\Atrue|false\Z/) val == "true" - elsif val.empty? - nil else val end diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 36cf20194c..97c11bd95d 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -352,7 +352,27 @@ if you believe they were disclosed to a third party. begin content = Bundler::YAMLSerializer.load(File.read(filename)) - unless content.is_a? Hash + if content.is_a? Hash + content.transform_keys! do |k| + if k.match?(/__/) + if k.is_a?(Symbol) + k.to_s.gsub(/__/,".").to_sym + else + k.dup.gsub(/__/,".") + end + else + k + end + end + + content.transform_values! do |v| + if (v.is_a?(Hash) || v.is_a?(String)) && v.empty? + nil + else + v + end + end + else warn "Failed to load #{filename} because it doesn't contain valid YAML hash" return {} end