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

ruby-changes:73750

From: Mike <ko1@a...>
Date: Wed, 28 Sep 2022 05:55:40 +0900 (JST)
Subject: [ruby-changes:73750] 8f7f12ad64 (master): [rubygems/rubygems] fix: Gem::Platform.match handles String argument properly

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

From 8f7f12ad64c2f01e1fc8a75402337ceeb6607657 Mon Sep 17 00:00:00 2001
From: Mike Dalessio <mike.dalessio@g...>
Date: Mon, 19 Sep 2022 15:39:32 -0400
Subject: [rubygems/rubygems] fix: Gem::Platform.match handles String argument
 properly

Previously 9eead86 introduced non-commutativity of platforms, and
later commit 1b9f7f50 changed the behavior of `Gem::Platform.match` to
ensure the callee of `#=~` was the gem platform.

However, when the platform argument is a String, then the callee and
argument of `#=~` are flipped (see docs for `String#=~`), which works
against the fix from 1b9f7f50.

Closes #5938

https://github.com/rubygems/rubygems/commit/3b1fb562e8
---
 lib/rubygems/platform.rb           | 1 +
 test/rubygems/test_gem_platform.rb | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb
index 06de5ded8d..1dacc596c4 100644
--- a/lib/rubygems/platform.rb
+++ b/lib/rubygems/platform.rb
@@ -22,6 +22,7 @@ class Gem::Platform https://github.com/ruby/ruby/blob/trunk/lib/rubygems/platform.rb#L22
   end
 
   def self.match_platforms?(platform, platforms)
+    platform = Gem::Platform.new(platform) unless platform.is_a?(Gem::Platform)
     platforms.any? do |local_platform|
       platform.nil? ||
         local_platform == platform ||
diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb
index f683204a2f..3bd4a862c5 100644
--- a/test/rubygems/test_gem_platform.rb
+++ b/test/rubygems/test_gem_platform.rb
@@ -452,6 +452,13 @@ class TestGemPlatform < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_platform.rb#L452
     assert_equal 1, result.scan(/@version=/).size
   end
 
+  def test_gem_platform_match_with_string_argument
+    util_set_arch "x86_64-linux-musl"
+
+    assert(Gem::Platform.match(Gem::Platform.new("x86_64-linux")), "should match Gem::Platform")
+    assert(Gem::Platform.match("x86_64-linux"), "should match String platform")
+  end
+
   def assert_local_match(name)
     assert_match Gem::Platform.local, name
   end
-- 
cgit v1.2.1


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

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