Skip to content

Commit

Permalink
[rubygems/rubygems] Added guard condition for replacing __ variable i…
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt authored and matzbot committed Apr 19, 2023
1 parent d0dc617 commit 30b3290
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/bundler/yaml_serializer.rb
Expand Up @@ -50,15 +50,15 @@ def dump_hash(hash)
$
/xo.freeze

def load(str)
def load(str, is_rubygems: false)
res = {}
stack = [res]
last_hash = nil
last_empty_key = nil
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)
key = convert_to_backward_compatible_key(key) unless is_rubygems
key = key[1..-1].to_sym if key.start_with?(":")
depth = indent.scan(/ /).length
if quote.empty? && val.empty?
Expand Down
14 changes: 1 addition & 13 deletions lib/rubygems/config_file.rb
Expand Up @@ -351,20 +351,8 @@ def load_file(filename)
return {} unless filename && !filename.empty? && File.exist?(filename)

begin
content = Bundler::YAMLSerializer.load(File.read(filename))
content = Bundler::YAMLSerializer.load(File.read(filename), is_rubygems: true)
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
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/helper.rb
Expand Up @@ -680,7 +680,7 @@ def load_yaml(yaml)

def load_yaml_file(file)
require "bundler/yaml_serializer"
Bundler::YAMLSerializer.load(File.read(file))
Bundler::YAMLSerializer.load(File.read(file), is_rubygems: true)
end

def all_spec_names
Expand Down

0 comments on commit 30b3290

Please sign in to comment.