summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2023-04-17 14:42:23 +0900
committergit <svn-admin@ruby-lang.org>2023-04-19 06:56:14 +0000
commit2014dc5e3aef50eb59b05138af8f0f72935c4f58 (patch)
tree3920a8d2f64b103d2fa20e4513c392834a803ed2 /lib
parent6f50ecfe664924c086879273a29a2ecea9e51683 (diff)
downloadruby-2014dc5e3aef50eb59b05138af8f0f72935c4f58.tar.gz
[rubygems/rubygems] Handle Symbol key and Interger and Boolean values
https://github.com/rubygems/rubygems/commit/63efdac045
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/yaml_serializer.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb
index d5ecbd4aef..492c8aaf54 100644
--- a/lib/bundler/yaml_serializer.rb
+++ b/lib/bundler/yaml_serializer.rb
@@ -13,7 +13,11 @@ module Bundler
def dump_hash(hash)
yaml = String.new("\n")
hash.each do |k, v|
- yaml << k << ":"
+ if k.is_a?(Symbol)
+ yaml << ":#{k}:"
+ else
+ yaml << k << ":"
+ end
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
@@ -55,6 +59,7 @@ module Bundler
if match = HASH_REGEX.match(line)
indent, key, quote, val = match.captures
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?
new_hash = {}
@@ -63,18 +68,28 @@ module Bundler
last_empty_key = key
last_hash = stack[depth]
else
- stack[depth][key] = val
+ stack[depth][key] = convert_to_ruby_value(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(val)
+ last_hash[last_empty_key].push(convert_to_ruby_value(val))
end
end
res
end
+ def convert_to_ruby_value(val)
+ if 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}