From 713397c93eb2d7a8e78ec0d6e40c0bd2803cc868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E5=8C=97?= Date: Wed, 11 Oct 2023 18:43:43 +0800 Subject: [PATCH] Fix semantic version comparison for mixed numeric and string prerelease segments --- lib/cocoapods-core/version.rb | 3 +++ spec/version_spec.rb | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/cocoapods-core/version.rb b/lib/cocoapods-core/version.rb index b65b3cae5..f2a12e690 100644 --- a/lib/cocoapods-core/version.rb +++ b/lib/cocoapods-core/version.rb @@ -225,6 +225,9 @@ def compare_segments(other) if comparison = lhs <=> rhs return comparison + else + return -1 if lhs.is_a?(Numeric) && rhs.is_a?(String) + return 1 if rhs.is_a?(Numeric) && lhs.is_a?(String) end end end diff --git a/spec/version_spec.rb b/spec/version_spec.rb index 725bda111..451033187 100644 --- a/spec/version_spec.rb +++ b/spec/version_spec.rb @@ -145,6 +145,9 @@ module Pod # Example from CocoaPods/CocoaPods#5718 Version.new('1.0-beta.8').should.be < Version.new('1.0-beta.8a') + + # Example from section 11.4.3 on semver.org + Version.new('1.0.0-beta.3rd.1').should.not.be >= Version.new('1.0.0-beta.ios17.1') end end