diff options
| -rw-r--r-- | lib/rubygems/specification.rb | 9 | ||||
| -rw-r--r-- | test/rubygems/test_gem_specification.rb | 8 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index abdc1dbf4b..3f132b6f2b 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -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 diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index e4e908c98f..6a893f09c9 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -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 |
