[rubygems/rubygems] Clear `YAML` constant if it was undefined previously

https://github.com/rubygems/rubygems/commit/31d0311258
This commit is contained in:
Nobuyoshi Nakada 2023-07-19 22:58:01 +09:00 коммит произвёл git
Родитель 84b5274143
Коммит 419fbc77e0
2 изменённых файлов: 16 добавлений и 1 удалений

Просмотреть файл

@ -1301,6 +1301,8 @@ class Gem::Specification < Gem::BasicSpecification
def self._load(str)
Gem.load_yaml
yaml_set = false
array = begin
Marshal.load str
rescue ArgumentError => e
@ -1313,7 +1315,10 @@ class Gem::Specification < Gem::BasicSpecification
message = e.message
raise unless message.include?("YAML::")
Object.const_set "YAML", Psych unless Object.const_defined?(:YAML)
unless Object.const_defined?(:YAML)
Object.const_set "YAML", Psych
yaml_set = true
end
if message.include?("YAML::Syck::")
YAML.const_set "Syck", YAML unless YAML.const_defined?(:Syck)
@ -1324,6 +1329,8 @@ class Gem::Specification < Gem::BasicSpecification
end
retry
ensure
Object.__send__(:remove_const, "YAML") if yaml_set
end
spec = Gem::Specification.new

Просмотреть файл

@ -1071,19 +1071,27 @@ dependencies: []
end
def test_handles_private_null_type
yaml_defined = Object.const_defined?("YAML")
path = File.expand_path "data/pry-0.4.7.gemspec.rz", __dir__
data = Marshal.load Gem::Util.inflate(Gem.read_binary(path))
assert_instance_of Gem::Specification, data
assert_equal(yaml_defined, Object.const_defined?("YAML"))
end
def test_handles_dependencies_with_syck_requirements_bug
yaml_defined = Object.const_defined?("YAML")
path = File.expand_path "data/excon-0.7.7.gemspec.rz", __dir__
data = Marshal.load Gem::Util.inflate(Gem.read_binary(path))
assert_instance_of Gem::Specification, data
assert_equal(yaml_defined, Object.const_defined?("YAML"))
end
def test_initialize