diff options
-rw-r--r-- | lib/bundler/settings.rb | 2 | ||||
-rw-r--r-- | lib/bundler/yaml_serializer.rb | 27 | ||||
-rw-r--r-- | lib/rubygems/config_file.rb | 38 | ||||
-rw-r--r-- | test/rubygems/helper.rb | 2 |
4 files changed, 43 insertions, 26 deletions
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 8c69e81490..1139eab503 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.to_s + config[new_k] = v config end end diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 23dce9440b..d5ecbd4aef 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -13,11 +13,7 @@ module Bundler def dump_hash(hash) yaml = String.new("\n") hash.each do |k, v| - if k.is_a?(Symbol) - yaml << ":#{k}:" - else - yaml << k << ":" - end + yaml << k << ":" if v.is_a?(Hash) yaml << dump_hash(v).gsub(/^(?!$)/, " ") # indent all non-empty lines elsif v.is_a?(Array) # Expected to be array of strings @@ -50,7 +46,7 @@ module Bundler $ /xo.freeze - def load(str, is_rubygems: false) + def load(str) res = {} stack = [res] last_hash = nil @@ -58,8 +54,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) unless is_rubygems - key = key[1..-1].to_sym if key.start_with?(":") + key = convert_to_backward_compatible_key(key) depth = indent.scan(/ /).length if quote.empty? && val.empty? new_hash = {} @@ -68,30 +63,18 @@ module Bundler last_empty_key = key last_hash = stack[depth] else - stack[depth][key] = convert_to_ruby_value(val) + stack[depth][key] = val end elsif match = ARRAY_REGEX.match(line) _, val = match.captures last_hash[last_empty_key] = [] unless last_hash[last_empty_key].is_a?(Array) - last_hash[last_empty_key].push(convert_to_ruby_value(val)) + last_hash[last_empty_key].push(val) end end res end - def convert_to_ruby_value(val) - if val.match?(/\A:(.*)\Z/) - val[1..-1].to_sym - elsif val.match?(/\A[+-]?\d+\Z/) - val.to_i - elsif val.match?(/\Atrue|false\Z/) - val == "true" - else - val - end - end - # for settings' keys def convert_to_backward_compatible_key(key) key = "#{key}/" if key =~ /https?:/i && key !~ %r{/\Z} diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 2191a81184..b5c4b4dcf4 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -320,6 +320,10 @@ if you believe they were disclosed to a third party. config = load_file(credentials_path).merge(host => api_key) + config.transform_keys! do |k| + k.is_a?(Symbol) ? ":#{k}" : k + end + dirname = File.dirname credentials_path require "fileutils" FileUtils.mkdir_p(dirname) @@ -351,10 +355,36 @@ if you believe they were disclosed to a third party. return {} unless filename && !filename.empty? && File.exist?(filename) begin - content = Bundler::YAMLSerializer.load(File.read(filename), is_rubygems: true) + content = Bundler::YAMLSerializer.load(File.read(filename)) if content.is_a? Hash + content.transform_keys! do |k| + if k.match?(/\A:(.*)\Z/) + k[1..-1].to_sym + elsif 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? + if v.is_a?(String) + if v.match?(/\A:(.*)\Z/) + v[1..-1].to_sym + elsif v.match?(/\A[+-]?\d+\Z/) + v.to_i + elsif v.match?(/\Atrue|false\Z/) + v == "true" + elsif v.empty? + nil + else + v + end + elsif v.is_a?(Hash) && v.empty? nil else v @@ -494,6 +524,10 @@ if you believe they were disclosed to a third party. yaml_hash[key.to_s] = value end + yaml_hash.transform_keys! do |k| + k.is_a?(Symbol) ? ":#{k}" : k + end + require "bundler/yaml_serializer" Bundler::YAMLSerializer.dump(yaml_hash) end diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index 39f8fae2fd..c1c0e19fa0 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -680,7 +680,7 @@ class Gem::TestCase < Test::Unit::TestCase def load_yaml_file(file) require "bundler/yaml_serializer" - Bundler::YAMLSerializer.load(File.read(file), is_rubygems: true) + Bundler::YAMLSerializer.load(File.read(file)) end def all_spec_names |