summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-19 22:58:01 +0900
committergit <svn-admin@ruby-lang.org>2023-07-19 23:20:54 +0000
commit419fbc77e0c05358f8eb22392cd99050c4dfaf5f (patch)
tree8952bad6cd1031140286dc8ea2080cda43510543
parent84b5274143bf54f77f9950eeba72a64cc761dd45 (diff)
[rubygems/rubygems] Clear `YAML` constant if it was undefined previously
https://github.com/rubygems/rubygems/commit/31d0311258
-rw-r--r--lib/rubygems/specification.rb9
-rw-r--r--test/rubygems/test_gem_specification.rb8
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