From 0af4d2d369ff580ef54839ec15a8c7ec419978cb Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 29 Dec 2019 15:41:23 +0000 Subject: [PATCH] Fix Gem::Specification#to_ruby without OpenSSL OpenSSL is an optional dependency of Ruby. Requiring openssl unconditionally means that Rubies that don't have the OpenSSL library won't be able to use RubyGems at all. In such a Ruby, an OpenSSL::PKey::RSA object can't exist, so we can just skip the check for those objects if there is no OpenSSL. --- lib/rubygems/specification.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index e1af1dfd0114..a9f192e3a7d1 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -2414,7 +2414,10 @@ def test_files # :nodoc: # still have their default values are omitted. def to_ruby - require 'openssl' + begin + require 'openssl' + rescue LoadError + end mark_version result = [] result << "# -*- encoding: utf-8 -*-" @@ -2454,7 +2457,9 @@ def to_ruby next if handled.include? attr_name current_value = self.send(attr_name) if current_value != default_value(attr_name) || self.class.required_attribute?(attr_name) - result << " s.#{attr_name} = #{ruby_code current_value}" unless current_value.is_a?(OpenSSL::PKey::RSA) + unless defined?(OpenSSL) && current_value.is_a?(OpenSSL::PKey::RSA) + result << " s.#{attr_name} = #{ruby_code current_value}" + end end end