[前][次][番号順一覧][スレッド一覧]

ruby-changes:63168

From: David <ko1@a...>
Date: Mon, 28 Sep 2020 14:54:55 +0900 (JST)
Subject: [ruby-changes:63168] c6bdf75049 (master): Disallow downgrades to too old versions

https://git.ruby-lang.org/ruby.git/commit/?id=c6bdf75049

From c6bdf750499491d12c947de546c164a854dd0703 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Tue, 28 Apr 2020 16:28:52 +0200
Subject: Disallow downgrades to too old versions

Consider the version original included with each ruby as the minimum
supported version.

diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb
index bac9c82..a822f09 100644
--- a/lib/rubygems/commands/update_command.rb
+++ b/lib/rubygems/commands/update_command.rb
@@ -74,6 +74,13 @@ command to remove old versions. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L74
     end
   end
 
+  def check_oldest_rubygems(version) # :nodoc:
+    if oldest_supported_version > version
+      alert_error "rubygems #{version} is not supported. The oldest supported version is #{oldest_supported_version}"
+      terminate_interaction 1
+    end
+  end
+
   def check_update_arguments # :nodoc:
     unless options[:args].empty?
       alert_error "Gem names are not allowed with the --system option"
@@ -214,7 +221,7 @@ command to remove old versions. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L221
     rubygems_update.version = version
 
     hig = {
-      'rubygems-update' => rubygems_update
+      'rubygems-update' => rubygems_update,
     }
 
     gems_to_update = which_to_update hig, options[:args], :system
@@ -272,6 +279,8 @@ command to remove old versions. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L279
 
     check_latest_rubygems version
 
+    check_oldest_rubygems version
+
     update_gem 'rubygems-update', version
 
     installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement
@@ -309,4 +318,10 @@ command to remove old versions. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L318
 
     result
   end
+
+  private
+
+  def oldest_supported_version
+    @oldest_supported_version ||= Gem::Version.new("2.5.2")
+  end
 end
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index 65a70b2..eed799c 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -158,6 +158,26 @@ class TestGemCommandsUpdateCommand < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_update_command.rb#L158
     assert_empty out
   end
 
+  def test_execute_system_specific_older_than_minimum_supported_rubygems
+    spec_fetcher do |fetcher|
+      fetcher.download 'rubygems-update', "2.5.1" do |s|
+        s.files = %w[setup.rb]
+      end
+    end
+
+    @cmd.options[:args]          = []
+    @cmd.options[:system]        = "2.5.1"
+
+    assert_raises Gem::MockGemUi::TermError do
+      use_ui @ui do
+        @cmd.execute
+      end
+    end
+
+    assert_empty @ui.output
+    assert_equal "ERROR:  rubygems 2.5.1 is not supported. The oldest supported version is 2.5.2\n", @ui.error
+  end
+
   def test_execute_system_specific_older_than_3_2_removes_plugins_dir
     spec_fetcher do |fetcher|
       fetcher.download 'rubygems-update', 3.1 do |s|
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]