[rubygems/rubygems] Bundler::YAMLSerializer.load couldn't raise error when invalid yaml was provided
https://github.com/rubygems/rubygems/commit/cfcfde04c7
This commit is contained in:
parent
92ab4e41dd
commit
8b95b33a9d
@ -521,51 +521,46 @@ if you believe they were disclosed to a third party.
|
|||||||
Bundler::YAMLSerializer.dump(content)
|
Bundler::YAMLSerializer.dump(content)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.load_with_rubygems_config_hash(hash)
|
def self.load_with_rubygems_config_hash(yaml)
|
||||||
require "bundler/yaml_serializer"
|
require "bundler/yaml_serializer"
|
||||||
|
|
||||||
content = Bundler::YAMLSerializer.load(hash)
|
content = Bundler::YAMLSerializer.load(yaml)
|
||||||
|
|
||||||
if content.is_a? Hash
|
content.transform_keys! do |k|
|
||||||
content.transform_keys! do |k|
|
if k.match?(/\A:(.*)\Z/)
|
||||||
if k.match?(/\A:(.*)\Z/)
|
k[1..-1].to_sym
|
||||||
k[1..-1].to_sym
|
elsif k.include?("__")
|
||||||
elsif k.include?("__")
|
if k.is_a?(Symbol)
|
||||||
if k.is_a?(Symbol)
|
k.to_s.gsub(/__/,".").gsub(%r{/\Z}, "").to_sym
|
||||||
k.to_s.gsub(/__/,".").gsub(%r{/\Z}, "").to_sym
|
|
||||||
else
|
|
||||||
k.dup.gsub(/__/,".").gsub(%r{/\Z}, "")
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
k
|
k.dup.gsub(/__/,".").gsub(%r{/\Z}, "")
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
k
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
content.transform_values! do |v|
|
content.transform_values! do |v|
|
||||||
if v.is_a?(String)
|
if v.is_a?(String)
|
||||||
if v.match?(/\A:(.*)\Z/)
|
if v.match?(/\A:(.*)\Z/)
|
||||||
v[1..-1].to_sym
|
v[1..-1].to_sym
|
||||||
elsif v.match?(/\A[+-]?\d+\Z/)
|
elsif v.match?(/\A[+-]?\d+\Z/)
|
||||||
v.to_i
|
v.to_i
|
||||||
elsif v.match?(/\Atrue|false\Z/)
|
elsif v.match?(/\Atrue|false\Z/)
|
||||||
v == "true"
|
v == "true"
|
||||||
elsif v.empty?
|
elsif v.empty?
|
||||||
nil
|
|
||||||
else
|
|
||||||
v
|
|
||||||
end
|
|
||||||
elsif v.is_a?(Hash) && v.empty?
|
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
elsif v.is_a?(Hash) && v.empty?
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
content
|
|
||||||
else
|
|
||||||
warn "Failed to load #{filename} because it doesn't contain valid YAML hash"
|
|
||||||
{}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
content
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -5,29 +5,6 @@ require "bundler/friendly_errors"
|
|||||||
require "cgi"
|
require "cgi"
|
||||||
|
|
||||||
RSpec.describe Bundler, "friendly errors" do
|
RSpec.describe Bundler, "friendly errors" do
|
||||||
context "with invalid YAML in .gemrc" do
|
|
||||||
before do
|
|
||||||
File.open(home(".gemrc"), "w") do |f|
|
|
||||||
f.write "invalid: yaml: hah"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
after do
|
|
||||||
FileUtils.rm(home(".gemrc"))
|
|
||||||
end
|
|
||||||
|
|
||||||
it "reports a relevant friendly error message" do
|
|
||||||
gemfile <<-G
|
|
||||||
source "#{file_uri_for(gem_repo1)}"
|
|
||||||
gem "rack"
|
|
||||||
G
|
|
||||||
|
|
||||||
bundle :install, :env => { "DEBUG" => "true" }
|
|
||||||
|
|
||||||
expect(err).to include("Failed to load #{home(".gemrc")}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "calls log_error in case of exception" do
|
it "calls log_error in case of exception" do
|
||||||
exception = Exception.new
|
exception = Exception.new
|
||||||
expect(Bundler::FriendlyErrors).to receive(:exit_status).with(exception).and_return(1)
|
expect(Bundler::FriendlyErrors).to receive(:exit_status).with(exception).and_return(1)
|
||||||
|
@ -465,21 +465,6 @@ if you believe they were disclosed to a third party.
|
|||||||
assert_equal %w[http://even-more-gems.example.com], Gem.sources
|
assert_equal %w[http://even-more-gems.example.com], Gem.sources
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ignore_invalid_config_file
|
|
||||||
File.open @temp_conf, "w" do |fp|
|
|
||||||
fp.puts "invalid: yaml:"
|
|
||||||
end
|
|
||||||
|
|
||||||
begin
|
|
||||||
verbose = $VERBOSE
|
|
||||||
$VERBOSE = nil
|
|
||||||
|
|
||||||
util_config_file
|
|
||||||
ensure
|
|
||||||
$VERBOSE = verbose
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_load_ssl_verify_mode_from_config
|
def test_load_ssl_verify_mode_from_config
|
||||||
File.open @temp_conf, "w" do |fp|
|
File.open @temp_conf, "w" do |fp|
|
||||||
fp.puts ":ssl_verify_mode: 1"
|
fp.puts ":ssl_verify_mode: 1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user