Skip to content

Commit 3b1fb56

Browse files
committed
fix: Gem::Platform.match handles String argument properly
Previously 9eead86 introduced non-commutativity of platforms, and later commit 1b9f7f5 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 1b9f7f5. Closes #5938
1 parent 7c1d788 commit 3b1fb56

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/rubygems/platform.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def self.match(platform)
2222
end
2323

2424
def self.match_platforms?(platform, platforms)
25+
platform = Gem::Platform.new(platform) unless platform.is_a?(Gem::Platform)
2526
platforms.any? do |local_platform|
2627
platform.nil? ||
2728
local_platform == platform ||

test/rubygems/test_gem_platform.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,13 @@ def test_inspect
452452
assert_equal 1, result.scan(/@version=/).size
453453
end
454454

455+
def test_gem_platform_match_with_string_argument
456+
util_set_arch "x86_64-linux-musl"
457+
458+
assert(Gem::Platform.match(Gem::Platform.new("x86_64-linux")), "should match Gem::Platform")
459+
assert(Gem::Platform.match("x86_64-linux"), "should match String platform")
460+
end
461+
455462
def assert_local_match(name)
456463
assert_match Gem::Platform.local, name
457464
end

0 commit comments

Comments
 (0)