Skip to content

Commit

Permalink
[rubygems/rubygems] Keep compatiblity of Bundler specs
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt authored and matzbot committed Apr 19, 2023
1 parent 364c2fe commit bf8d8ce
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/bundler/settings.rb
Expand Up @@ -461,7 +461,7 @@ def load_config(config_file)
new_k = k.gsub("-", "___")
end

config[new_k] = v
config[new_k] = v.to_s
config
end
end
Expand Down
19 changes: 1 addition & 18 deletions lib/bundler/yaml_serializer.rb
Expand Up @@ -58,7 +58,7 @@ def load(str)
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?
Expand All @@ -77,33 +77,16 @@ def load(str)
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
elsif val.match?(/\A[+-]?\d+\Z/)
val.to_i
elsif val.match?(/\Atrue|false\Z/)
val == "true"
elsif val.empty?
nil
else
val
end
Expand Down
22 changes: 21 additions & 1 deletion lib/rubygems/config_file.rb
Expand Up @@ -352,7 +352,27 @@ def load_file(filename)

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
Expand Down

0 comments on commit bf8d8ce

Please sign in to comment.